Hi all,
I`m doing a project in ASP.net
How to create a remember me cookie?
code follows...
pls correct the errors in it?
protected void cmdlogin_Click(object sender, EventArgs e)
{
dt = obj.execquery("SELECT i_userid, u_username, u_password FROM user_tbl");
for (int i = 0; i < dt.Rows.Count; i++)
{
if ((txtname.Text == dt.Rows[i]["u_username"].ToString()) && (txtpswd.Text == dt.Rows[i]["u_password"].ToString()))
{
if (FormsAuthentication.Authenticate(txtname.Text, txtpswd.Text))
FormsAuthentication.RedirectFromLoginPage(txtname.Text, chkpersist.Checked);
}
else
{
Label1.Visible = true;
Label1.Text = "Invalid Login";
}
}
if ((this.chkpersist.Checked))
{
//Check if the browser support cookies
if ((Request.Browser.Cookies))
{
if ((Request.Cookies["PBLOGIN"] != null))
{
if (Request.Cookies["username"] != null)
{
if (FormsAuthentication.Authenticate(txtname.Text, txtpswd.Text))
{
FormsAuthentication.RedirectFromLoginPage(txtname.Text, chkpersist.Checked);
//FormsAuthentication.RedirectFromLoginPage(txtname.Text, false );
}
}
}
//Check if the cookie with name PBLOGIN exist on user's machine
else if ((Request.Cookies["PBLOGIN"] == null))
{
//Create a cookie with expiry of 30 days
Response.Cookies["PBLOGIN"].Expires = DateTime.Now.AddDays(30);
//Write username to the cookie
Response.Cookies["username"].Value = txtname.Text;
Response.Cookies["pswd"].Value = txtpswd.Text;
}
//If the cookie already exist then write the user name and password on the cookie
else
{
Response.Cookies["username"].Value = txtname.Text;
Response.Cookies["pswd"].Value = txtpswd.Text;
}
}
}
Pls help me
Thanks in advance