Hi,
I have a problem to do this, I am describing the scenario below:-
(1) I have an asp:login control in my aspx page
<asp:Login ID="Login1" runat="server" onauthenticate="Login1_Authenticate" FailureAction="RedirectToLoginPage">
</asp:Login>
(2) The code-behind is
public void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
bool Authenticated = false;
Authenticated = SiteSpecificAuthenticationMethod(Login1.UserName, Login1.Password);
e.Authenticated = Authenticated;
}
public bool SiteSpecificAuthenticationMethod(string username, string pass)
{
string userid = username;
string password = pass;
//string connstr = "Data Source=ARKA-PC;Initial Catalog=rgdb;User Id = sa;password = 12345";
//getting data from web.config file
string connstr = ConfigurationManager.ConnectionStrings["TestConnectionString1"].ConnectionString;
SqlConnection conn = new SqlConnection(connstr);
SqlCommand cmd = new SqlCommand();
conn.Open();
cmd = new SqlCommand("Select name,password WHERE name='@userid' AND password='@password'", conn);
cmd.Parameters.AddWithValue("@userid", Login1.UserName);
cmd.Parameters.AddWithValue("@password", Login1.Password);
if (str1 == "admin" && str2 == "admin")
{
Session["user"] = "admin";
Response.Redirect("Products.aspx");
return true;
}
else
{
//Response.Write("invalid login");
return false;
}
conn.Close();
}
(3) I have a database known as "Stepsample" in which i have one table containing two fields. One is name and password(both username and password is admin).
(4) Now i want to check if one tries to login via invalid credentials via a stored procedure.
Please let me know how to check the username and password stored in the database and validate it......
Any help is appreciated..
Thanks and Regards
Akiii