Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 949309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:23:03+00:00 2026-05-15T23:23:03+00:00

I have implemented remember me option in my asp.net webform by using this, protected

  • 0

I have implemented remember me option in my asp.net webform by using this,

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

Am i doing it the right way? Any suggestion.. I am using windows authentication and i am not using asp.net membership..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T23:23:04+00:00Added an answer on May 15, 2026 at 11:23 pm

    Rather than directly storing the username and password in the cookie, store the username and a hash of the password and a salt in the cookie, then when you authenticate the cookie, retrieve the password for the given username, re-create the hash with the password and the same salt and compare them.

    Creating the hash is as simple as storing the password and salt values together in a string, converting the string to a byte array, computing the hash of the byte array (using MD5 or whatever you prefer) and converting the resulting hash to a string (probably via base64 encoding).

    Here’s some example code:

    // Create a hash of the given password and salt.
    public string CreateHash(string password, string salt)
    {
        // Get a byte array containing the combined password + salt.
        string authDetails = password + salt;
        byte[] authBytes = System.Text.Encoding.ASCII.GetBytes(authDetails);
    
        // Use MD5 to compute the hash of the byte array, and return the hash as
        // a Base64-encoded string.
        var md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
        byte[] hashedBytes = md5.ComputeHash(authBytes);
        string hash = Convert.ToBase64String(hashedBytes);
    
        return hash;
    }
    
    // Check to see if the given password and salt hash to the same value
    // as the given hash.
    public bool IsMatchingHash(string password, string salt, string hash)
    {
        // Recompute the hash from the given auth details, and compare it to
        // the hash provided by the cookie.
        return CreateHash(password, salt) == hash;
    }
    
    // Create an authentication cookie that stores the username and a hash of
    // the password and salt.
    public HttpCookie CreateAuthCookie(string username, string password, string salt)
    {
        // Create the cookie and set its value to the username and a hash of the
        // password and salt. Use a pipe character as a delimiter so we can
        // separate these two elements later.
        HttpCookie cookie = new HttpCookie("YourSiteCookieNameHere");
        cookie.Value = username + "|" + CreateHash(password, salt);
        return cookie;
    }
    
    // Determine whether the given authentication cookie is valid by
    // extracting the username, retrieving the saved password, recomputing its
    // hash, and comparing the hashes to see if they match. If they match,
    // then this authentication cookie is valid.
    public bool IsValidAuthCookie(HttpCookie cookie, string salt)
    {
        // Split the cookie value by the pipe delimiter.
        string[] values = cookie.Value.Split('|');
        if (values.Length != 2) return false;
    
        // Retrieve the username and hash from the split values.
        string username = values[0];
        string hash = values[1];
    
        // You'll have to provide your GetPasswordForUser function.
        string password = GetPasswordForUser(username);
    
        // Check the password and salt against the hash.
        return IsMatchingHash(password, salt, hash);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.