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 4123424
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:36:34+00:00 2026-05-20T23:36:34+00:00

Can’t find answer to my question. I’m creating registration and need autologin for user

  • 0

Can’t find answer to my question.
I’m creating registration and need autologin for user with cookie.
What kind of information should be stored in cookie? Is it username + hash password or what

  • 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-20T23:36:35+00:00Added an answer on May 20, 2026 at 11:36 pm

    First, just to echo what everyone else has said, this isn’t so much an auto-login feature as it is a ‘remember me if I navigate away from the page’ feature.

    How I have seen it done in the past is similar to the implementation explained by frostymarvelous. Basically I have seen 3 cookies used:

    Cookie 1:

    • name – ‘username’
    • value – user’s name

    Cookie 2:

    • name – ‘salt’
    • value – random salt created for this particular login

    Cookie 3:

    • name – ‘authentication_hash’
    • value – Hash of a couple unique pieces of data that only your website can duplicate. If you can duplicate this value in the cookie, then make sure the user doesn’t have to login again.

    Basically, cookie 3 is the most important cookie and I would include a couple things in this to prevent it from being duplicated easily:

    <?php 
    function isAuthenticationCookieValid() {
        // $websitePassword would be a unique string stored in a file that is only
        // accessible by the server running your website. 
        include("websitePassword.php");
    
        // $hashOfUserPassword should be a hash of the user's password and should be
        // retrieved from the database in hashed form because that is how you should
        // store passwords.
        $hashOfUserPassword = retrieveUserPasswordFromDatabase($_COOKIE['username']);
    
        // $salt should just be read from cookie.
        $salt = $_COOKIE['salt'];
    
        $authenticationValue = sha1($websitePassword . $salt . $hashOfUserPassword);
    
        // Compare authentication value in cookie with calculated authentication value.
        return $authenticationValue == $_COOKIE['authentication_hash'];
    }
    ?>
    

    The contents of ‘websitePassword.php’ should just be:

    <?php
        $websitePassword = "secretWebsitePassword";  // Obviously use a better password
    ?>
    

    I would also suggest making the cookies expire after a timelimit to make your website more secure and you could possibly add a time element to your hash so if they try to use that particular hash after a particular amount of time, they will not be logged in automatically.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anybody help me? What should be the datatype for this type -07:00:00 of
Can anyone (maybe an XSL-fan?) help me find any advantages with handling presentation of
can you recommend some good ASP.NET tutorials or a good book? Should I jump
Can you tell me what is the difference between abstraction and information hiding in
Can not find scala.actors package in latest milestones, while it still presents in scaladocs:
Can find why i get this error can someone help? package Android.data; public class
Can anyone help me trying to find out why this doesn't work. The brushes
Can anyone let me know how can we change the value of kendo combobox
Can I order my users in the database, so I don't have to say
Can I change the field public virtual ClassOne ClassOne { get; set; } to

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.