Simple login page code with database connection

Posted by Abhisekjani under ASP.NET on 12/30/2011 | Points: 10 | Views : 14433 | Status : [Member] | Replies : 1
Hi....
i have developed a simple login page....i want to take the values to the data base.how to take login entry to database.....plz with code....reply




Responses

Posted by: Sksamantaray on: 12/30/2011 [Member] Silver | Points: 25

Up
0
Down
//when you click on Login Button
protected void btnUserAuthentication_Click(object sender, EventArgs e)
{


BusinessAccessClass bao = new BusinessAccessClass();
//this.lblErrMsg.Text = "";
string uname = txtUserName.Text.Trim();
string pword = bao.base64Encode(txtPassword.Text.Trim()); //here you can use your logic or md5 or password scheme
validateUser(uname, pword);


}

protected void validateUser(string username, string password)
{
//lblErrMsg.Text = "";
DataAccessClass dao = new DataAccessClass();
SqlParameter paramUname = new SqlParameter("@userName", username);
SqlParameter paramPassword = new SqlParameter("@password", password);
SqlParameter[] loginInfo = new SqlParameter[2] { paramUname, paramPassword };
DataSet ds = new DataSet();
try
{
ds = dao.ExecuteSelect("[spLogin]", loginInfo);

if (ds.Tables[0].Rows.Count == 0)
{
this.txtUserName.Focus();
}

if (ds.Tables[0].Rows.Count > 0)
{

Session["UserID"] = ds.Tables[0].Rows[0]["UserID"].ToString().Trim();
Session["UserName"] = ds.Tables[0].Rows[0]["UserName"].ToString().Trim();
if (Session["ParentCategory"] != null)
{

Response.Redirect("AddItem.aspx");
}
else
{
Response.Redirect("Home.aspx");
}


}
}
catch (Exception ex)
{
//lblErrMsg.Text = ex.Message.ToString();
//lblErrMsg.ForeColor = Color.Red;

}
finally
{
ds.Dispose();
}

}

Thanks,
Sanjay

Abhisekjani, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response