Click here to Skip to main content
15,904,416 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi folk's



Remember me functionality is not working fine,if checked the remember me and i login
and if i again i will like to login username and password remains there in the fields and the remember me as checked

my code is in his way...............
All this Code is in page load it self
(problem is fields are not remains and remember me is not checked ,can any one help me)
C#
protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.Cookies["UName"] != null)
                txt_username.Text = Request.Cookies["UName"].Value;
            if (Request.Cookies["PWD"] != null)
                txt_password.Attributes.Add("value", Request.Cookies["PWD"].Value);
            if (Request.Cookies["UName"] != null && Request.Cookies["PWD"] != null)
                chk_rem.Checked = true;
        }

        if (chk_rem.Checked == true)
        {
            Response.Cookies["UName"].Value = txt_username.Text;
            Response.Cookies["PWD"].Value = txt_password.Text;
            Response.Cookies["UName"].Expires = DateTime.Now.AddMonths(2);
            Response.Cookies["PWD"].Expires = DateTime.Now.AddMonths(2);
        }
        else
        {
            Response.Cookies["UName"].Expires = DateTime.Now.AddMonths(-1);
            Response.Cookies["PWD"].Expires = DateTime.Now.AddMonths(-1);
        }


    }
Posted
Comments
bhagirathimfs 4-Sep-12 3:34am    
In the Login Button when successfully logged in than set the Uname and PWD of cookie.

ASP
protected void Page_Load(object sender, EventArgs e)
    {
        HttpCookie cookie = Request.Cookies["Pr"];
        if (cookie == null)
        {
            Label1.Text = "<b>Unknown Customer</b>";
        }
        else
        {
            Label1.Text = "<b>Cookie Found.</b><br><br>";
            Label1.Text += "Welcome, " + cookie["Name"];
        }

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        HttpCookie cookie = Request.Cookies["Pr"];
        if (cookie == null)
        {
            cookie = new HttpCookie("Pr");
        }

        cookie["Name"] = TextBox1.Text;
        cookie.Expires = DateTime.Now.AddYears(1);
        Response.Cookies.Add(cookie);

        Label1.Text = "<b>Cookie Created.</b>";
        Label1.Text += "New Customer: " + cookie["Name"];

    }


this code will help you.
 
Share this answer
 
My friend, If you are creating this type of Page for Some Client, I think, you are doing very wrong type work on Security. Storing Cookies at Client System with Username and Password.

By the way, Remember Me function Creates a Persistent Cookie instead of Sessional cookie. So Just increase a Session Time out period.

Now create a Cookie with any GUID or Hash value of Name+Date etc. Store it in client system and Search for Cookie at Page Load event, if found just Get Username from Cookie and log in to user escaping login Process.
 
Share this answer
 
Inside the Submit button click event write these code instate of writing in page load event.
C#
if (chk_rem.Checked == true)
{
    Response.Cookies["UName"].Value = txt_username.Text;
    Response.Cookies["PWD"].Value = txt_password.Text;
    Response.Cookies["UName"].Expires = DateTime.Now.AddMonths(2);
    Response.Cookies["PWD"].Expires = DateTime.Now.AddMonths(2);
}
else
{
    Response.Cookies["UName"].Expires = DateTime.Now.AddMonths(-1);
    Response.Cookies["PWD"].Expires = DateTime.Now.AddMonths(-1);
}

Suggestion:
Please don't store UserName and Password directly inside the cookie.
Either encrypt the username and password or store a GUID .
 
Share this answer
 
v2

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