Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it secure to store passwords in cookies?

My web application's home page has a RememberMe checkbox. If the user checks it, I willl store email-id and password in cookies. This is my code:

if (this.ChkRememberme != null && this.ChkRememberme.Checked == true)    {      HttpCookie cookie = new HttpCookie(TxtUserName.Text, TxtPassword.Text);      cookie.Expires.AddYears(1);      Response.Cookies.Add(cookie);    } 

What I want to know is:

  • Is it secure to store passwords in cookies?
  • What is proper way of doing the same?
  • What are the best practices in setting time for a cookie?
like image 573
ACP Avatar asked Jan 20 '10 09:01

ACP


People also ask

Are credentials stored in cookies?

They never store your password, encrypted or not, in a cookie.

Are passwords stored in cookies or cache?

Your passwords are stored in the Password Manager. Your login status is stored in special cookies. The cache is where the browser stores temporary website information. Your passwords are stored in the Password Manager.

Are cookies a security risk?

Since the data in cookies doesn't change, cookies themselves aren't harmful. They can't infect computers with viruses or other malware. However, some cyberattacks can hijack cookies and enable access to your browsing sessions. The danger lies in their ability to track individuals' browsing histories.

What should not be stored in cookies?

Anything that should remain secure shouldn't be stored. That includes passwords, credit card numbers, social security numbers, etc.


1 Answers

It's NOT secure to store passwords in cookies because they are available as plain text.

A good place to find some answers about cookies is Cookie Central. For membership usually is used a cookie with a long string called 'token' that is issued from the website when you provide your user name and password. More about the process you can find in this article. When using forms authentication in ASP.NET you can set the authentication cookie like this:

FormsAuthentication.SetAuthCookie(userName, isPersistanceCookie); 

The second parameter is used for "Remember Me" functionality - if true it will create persistent cookies that will last after you leave the site. You can also programatically manipulate the cookie like this:

HttpCookie authCookie =   HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName]; 
like image 59
Branislav Abadjimarinov Avatar answered Sep 24 '22 10:09

Branislav Abadjimarinov