I have a registration form
where user is providing
his
1.email
2.userid
3.password
I am saving this data
in login table.how I can use
these deatils with
login control
provided by asp.net,I mean,details
which are provided by user
via registration form(i.e email,userid,and paasword),how can I use these details with Login control provided by asp.net.
// read the coonection string from web.config
string conString = ConfigurationManager.ConnectionStrings["ConnectionStringName"].ConnectionString;
using (System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(conString))
{
//' declare the command that will be used to execute the select statement
SqlCommand com = new SqlCommand("SELECT UserName FROM Users WHERE UserName = @UserName AND Password = @Password", con);
// set the username and password parameters
com.Parameters.Add("@UserName", SqlDbType.NVarChar).Value = userName;
com.Parameters.Add("@Password", SqlDbType.NVarChar).Value = password;
con.Open();
//' execute the select statment
string result =Convert.ToString( com.ExecuteScalar());
//' check the result
if (string.IsNullOrEmpty(result))
{
//invalid user/password , return flase
return false;
}
else
{
// valid login
return true;
}
}
}
BAAZ.
Mark answer if it helps.
Marked as answer by vineeta_2010 on May 04, 2012 02:49 PM
vineeta_2010
Member
149 Points
153 Posts
How to integrate Login control with my database on sql server?
May 03, 2012 06:08 AM|LINK
I have a registration form
where user is providing
his
1.email
2.userid
3.password
I am saving this data
in login table.how I can use
these deatils with
login control
provided by asp.net,I mean,details
which are provided by user
via registration form(i.e email,userid,and paasword),how can I use these details with Login control provided by asp.net.
I am using c#.
ramesh866
Participant
1467 Points
375 Posts
Re: How to integrate Login control with my database on sql server?
May 03, 2012 07:26 AM|LINK
Refer this link http://forums.asp.net/t/1403132.aspx/1
ziaulrahman
Member
483 Points
179 Posts
Re: How to integrate Login control with my database on sql server?
May 03, 2012 07:57 AM|LINK
Presentation layer code
protected void Login1_Authenticate(object sender, System.Web.UI.WebControls.AuthenticateEventArgs e)
{
string userName = Login1.UserName;
string password = Login1.Password;
bool result = UserLogin(userName, password);
if ((result))
{
e.Authenticated = true;
}
else
{
e.Authenticated = false;
}
}
---------------------------------------------------------------------------------------------------------------------------------------------------------
Component code
private bool UserLogin(string userName, string password)
{
// read the coonection string from web.config
string conString = ConfigurationManager.ConnectionStrings["ConnectionStringName"].ConnectionString;
using (System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(conString))
{
//' declare the command that will be used to execute the select statement
SqlCommand com = new SqlCommand("SELECT UserName FROM Users WHERE UserName = @UserName AND Password = @Password", con);
// set the username and password parameters
com.Parameters.Add("@UserName", SqlDbType.NVarChar).Value = userName;
com.Parameters.Add("@Password", SqlDbType.NVarChar).Value = password;
con.Open();
//' execute the select statment
string result =Convert.ToString( com.ExecuteScalar());
//' check the result
if (string.IsNullOrEmpty(result))
{
//invalid user/password , return flase
return false;
}
else
{
// valid login
return true;
}
}
}
Mark answer if it helps.
vineeta_2010
Member
149 Points
153 Posts
Re: How to integrate Login control with my database on sql server?
May 04, 2012 02:50 PM|LINK
thanx ramesh and zia..:)