Hi,
Below is the code for checking against user name and password in asp.net and sql server {Link Removed}
CODE
<h2>Login</h2>
<b>Username:</b>
<br/>
<asp:TextBox
ID="txtUsername"
CssClass="formfield"
runat="Server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
ControlToValidate="txtUsername"
Text="Required!"
runat="Server" />
<br />
<asp:Label
ID="lblError"
EnableViewState="False"
forecolor="red"
font-bold="True"
runat="Server" />
<br />
<b>Password:</b>
<br/>
<asp:TextBox
ID="txtPassword"
TextMode="password"
CssClass="formfield"
runat="Server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2"
ControlToValidate="txtPassword"
Text="Required!"
runat="Server" />
<br />
<asp:CheckBox Text="Automatically remember me"
ID="chkPersist"
Checked="True"
runat="Server" />
<br /><br />
<asp:Button ID="Button1"
Text="Login!"
OnClick="Button_Click"
runat="Server" />
void Button_Click(object sender, System.EventArgs e)
{
if (Page.IsValid)
{
switch (VerifyPassword( txtUsername.Text, txtPassword.Text )) {
case 0:
FormsAuthentication.RedirectFromLoginPage( txtUsername.Text, chkPersist.Checked );
break;
case 1:
lblError.Text = "You did not enter a valid username";
break;
case 2:
lblError.Text = "You did not enter a valid password";
break;
}
}
}
int VerifyPassword( string strUsername, string strPassword ) {
string strConString;
SqlConnection conJobs;
SqlCommand cmdVerify;
SqlParameter parmReturn;
strConString = "Data Source=202.71.129.59;database=jobskenabc;User ID=jobsken123;Password=cd546dc;";
conJobs = new SqlConnection( strConString );
cmdVerify = new SqlCommand( "VerifyPassword", conJobs );
cmdVerify.CommandType = CommandType.StoredProcedure;
parmReturn = cmdVerify.Parameters.Add( "@return", SqlDbType.Int );
parmReturn.Direction = ParameterDirection.ReturnValue;
cmdVerify.Parameters.Add( "@username", strUsername );
cmdVerify.Parameters.Add( "@password", strPassword );
conJobs.Open();
cmdVerify.ExecuteNonQuery();
conJobs.Close();
return (int)cmdVerify.Parameters["@return"].Value;
}
</script>
The above code check username and password against database.
In the statement, FormsAuthentication.RedirectFromLoginPage, FormsAuthentication is the class and RedirectFromLoginPage is the method. Calling the RedirectFromLoginPage method performs two actions. First, it creates a cookie on the user's browser that contains an Authentication Ticket. chkPersist. The statement Checked is true, it creates persistent cookie otherwise session cookie. Second :the RedirectFromLoginPage method also automatically redirets the user back to the page that sent him to the Login.aspx page in the first place by using a browser redirect.
This post has been edited by PsychoCoder: 13 Mar, 2008 - 04:06 AM