Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Saving User Name And Password.

Saving User Name And Password.

Scheduled Pinned Locked Moved ASP.NET
help
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Pranav Thakur
    wrote on last edited by
    #1

    Hi, I have written a code to save username and password on client machien using cookie.The code is as follows:- HttpCookie loginCookie = new HttpCookie("logCoockie"); if (this.Login1.RememberMeSet) { //Check if the browser support cookies if ((Request.Browser.Cookies)) { //Check if the cookie with name LoginCookie exist on user's machine //if (loginCookie == null) //{ //Create a cookie with expiry of 30 days loginCookie.Expires = DateTime.Now.AddDays(30); //Write username to the cookie loginCookie.Values.Add("UNAME", this.Login1.UserName.ToString()); //Write password to the cookie loginCookie.Values.Add("UPASS", this.Login1.Password.ToString()); //} //If the cookie already exist then wirte the user name and password on the cookie //else //{ // loginCookie.Values.Add("UNAME",this.Login1.UserName.ToString()); // loginCookie.Values.Add("UPASS",this.Login1.Password.ToString()); //} } Response.Cookies.Add(loginCookie); } else { Response.Cookies["logCoockie"].Expires = DateTime.Now.AddDays(-3); } But it is not recommended to save such information in cookie.Can anyone help to use any alternative way to save such inforamtion. Thanks.

    L C 2 Replies Last reply
    0
    • P Pranav Thakur

      Hi, I have written a code to save username and password on client machien using cookie.The code is as follows:- HttpCookie loginCookie = new HttpCookie("logCoockie"); if (this.Login1.RememberMeSet) { //Check if the browser support cookies if ((Request.Browser.Cookies)) { //Check if the cookie with name LoginCookie exist on user's machine //if (loginCookie == null) //{ //Create a cookie with expiry of 30 days loginCookie.Expires = DateTime.Now.AddDays(30); //Write username to the cookie loginCookie.Values.Add("UNAME", this.Login1.UserName.ToString()); //Write password to the cookie loginCookie.Values.Add("UPASS", this.Login1.Password.ToString()); //} //If the cookie already exist then wirte the user name and password on the cookie //else //{ // loginCookie.Values.Add("UNAME",this.Login1.UserName.ToString()); // loginCookie.Values.Add("UPASS",this.Login1.Password.ToString()); //} } Response.Cookies.Add(loginCookie); } else { Response.Cookies["logCoockie"].Expires = DateTime.Now.AddDays(-3); } But it is not recommended to save such information in cookie.Can anyone help to use any alternative way to save such inforamtion. Thanks.

      L Offline
      L Offline
      l0kke
      wrote on last edited by
      #2

      why do you need to store this on client side? there might be better solution for that. if you really need to store this in a cookie, then you have to encrypt the information at least. check eric newton's article on cookie encryption: http://www.codeproject.com/KB/web-security/HttpCookieEncryption.aspx[^]

      P 1 Reply Last reply
      0
      • P Pranav Thakur

        Hi, I have written a code to save username and password on client machien using cookie.The code is as follows:- HttpCookie loginCookie = new HttpCookie("logCoockie"); if (this.Login1.RememberMeSet) { //Check if the browser support cookies if ((Request.Browser.Cookies)) { //Check if the cookie with name LoginCookie exist on user's machine //if (loginCookie == null) //{ //Create a cookie with expiry of 30 days loginCookie.Expires = DateTime.Now.AddDays(30); //Write username to the cookie loginCookie.Values.Add("UNAME", this.Login1.UserName.ToString()); //Write password to the cookie loginCookie.Values.Add("UPASS", this.Login1.Password.ToString()); //} //If the cookie already exist then wirte the user name and password on the cookie //else //{ // loginCookie.Values.Add("UNAME",this.Login1.UserName.ToString()); // loginCookie.Values.Add("UPASS",this.Login1.Password.ToString()); //} } Response.Cookies.Add(loginCookie); } else { Response.Cookies["logCoockie"].Expires = DateTime.Now.AddDays(-3); } But it is not recommended to save such information in cookie.Can anyone help to use any alternative way to save such inforamtion. Thanks.

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        I would store a GUID on the client side and map that to a user in my database, so that the cookie maps to the login, without anyone being able to access the login from there.

        Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

        1 Reply Last reply
        0
        • L l0kke

          why do you need to store this on client side? there might be better solution for that. if you really need to store this in a cookie, then you have to encrypt the information at least. check eric newton's article on cookie encryption: http://www.codeproject.com/KB/web-security/HttpCookieEncryption.aspx[^]

          P Offline
          P Offline
          Pranav Thakur
          wrote on last edited by
          #4

          Thanks for your reply. Actually I want to know other better ways to save username and password without using cookies.Please help.

          L 1 Reply Last reply
          0
          • P Pranav Thakur

            Thanks for your reply. Actually I want to know other better ways to save username and password without using cookies.Please help.

            L Offline
            L Offline
            l0kke
            wrote on last edited by
            #5

            I agree with Chrisitan's post below, that's how I would do it probably, but I still don't know what is your scenario, so there could be better way how to achieve what you need.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups