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

if you are working with vs studio 2005 and .net framework 2.0, you dont have to do none of these. they are al made ready for you.

Thanks for the reply
I`m using VS2005.
pls tell how it`s possible?

ok, there is a login section in the tool box. there all the required tools are. drag and drop create user control first, then you may play around with others after you created your first user. there is a video tutorial on this topic in http://www.asp.net
give it a try, you will see it is easy.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.