Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to code a login page when user enter username and userpasword the system chek it with database data and if correct then goes or proced to next page
plz i have no idea about it .
Mian Sahib Jan
Posted

Get the username and password in two text fields. Create a stored procedure that will check that username and password combination exists in database. If a matching record is found then store the user id in a session variable and redirect the user to the next page and check the session variable on all subsequent pages. Otherwise display a message to the user on the login page itself.
 
Share this answer
 
Comments
Mian Sahib Jan 4-Apr-14 8:17am    
yes this is the best way if you dont mind sir, can you give a simple code because i have no idea about that plzz
Mian Sahib Jan 4-Apr-14 8:42am    
private void Login()
{
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=PRODUCT;Integrated Security=True");
if (con.State == ConnectionState.Closed)
{
con.Open();
}
if (txtUserName.Text == "" & txtPassword.Text == "")
{
lblMsg.Text = "User ID and Password is Required!";
}
DataSet ds = new DataSet();
//SqlDataAdapter da = new SqlDataAdapter();
string qry=("select UserName,UserPassword from tbl_Login where UserName='"+txtUserName.Text +"', and UserPassword='"+ txtPassword.Text+"'");
//SqlDataAdapter da = new SqlDataAdapter(qry,con);
// if (da.Fill(ds,"")
// {
// Response.Redirect("ItemAddrepeter.aspx");

// }
SqlCommand cmd = new SqlCommand(qry,con);
cmd.CommandType = CommandType.Text;
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
Session["Name"] = txtUserName.Text.ToString();
Session["pass"] = txtPassword.Text.ToString();
Response.Redirect("ItemAddrepeter.aspx");
}

con.Close();
}



protected void btnLogIn_Click(object sender, EventArgs e)
{
try
{
Login();
}
catch (Exception ex)
{
lblMsg.Text = ex.Message;
}
}
this is my code but this give error
 
Share this answer
 
Comments
Mian Sahib Jan 4-Apr-14 9:05am    
thanks Peter Leow

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900