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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:35:26+00:00 2026-05-17T23:35:26+00:00

I have a classifieds website which I am creating a login system for… In

  • 0

I have a classifieds website which I am creating a login system for…

In the code below, a form with “username” and “password” has been submitted to. Also a “remember_me” feature is available (Code is not tested yet):

else if($row['password']===$pass){
    session_start();
    $_SESSION['logged_in'] = '1';
    $remember_me = isset($_POST['remember']) ? $_POST['remember'] : '0';
    if($remember_me=='1'){

        $text = "SECRET_TEXT_AND_NUMBERS_HERE";
        $username= $row['username'];

        $salt1 = sha1($row['alt_username']);
        $salt2 = sha1($text);

        $cookie_value = $salt1.':'.$username.':'.sha1($row['alt_username'].$salt2.$salt1);

        setcookie("s_b", $cookie_value, time()+60*60*24*100, "/");

    }

}

Now, is this code a good start for a login page?

Also, an important follow-up question to all this, if users want to stay logged in, do I then set a $_SESSION variable like the one in the code, and just check if that is set in the beginning of all pages on the site?

 if(isset($_SESSION['logged_in'])) // Then user is logged in already

or do I check to see if the cookie created in the login page is set instead of checking the session?

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

    logging in is about security; security is always more difficult then it seems.

    There are a couple of things that you could improve in your code. first:

    the security for your password is in the strength of the hasing algorithm. You choose to use sha1 (better than md5, but could be improved by using sha256 or bCrypt if you use PHP version >= 5.3)

    First
    The salt you use is supposed to be a random value, stored alongside the hashed result.
    in other words, the value to store in your database is:

    $salt = [some random string of predifend lenght]; // Let's say 16 characters in length
    $storedValue = $salt . sha256($salt . $password);
    

    you check the password:

    if ($row['username'] == $_POST['username']  && substr($row['$storedValue'], 16) == sha256(substr($row['$storedValue'], 0, 16) . $_POST['password'])) {
        // login ok
    } else {
        // login fail
    }
    

    (better yet)
    Use a proven library for the password hashing stuff, take a look at: Portable PHP password hashing framework and try to use the CRYPT_BLOWFISH algorithm if at all popssible.

    Second
    You should only store the session key in the session cookie. all other information is stored on the server.
    The session cookie is already send out by PHP’s session_start() function call, so you do not have to worry about this anymore.

    if you want to check the sessions lifetime, you should store this information in the session array:

    $_SESSION['lastActivity'] =  time()+60*60*24*100;
    

    Third
    The remember me token is a ‘password equivalent’ so you should only store a hash of the token in your database, just treat it as a password, only this ‘password’ is not typed by the user, but read from the cookie.

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

Sidebar

Related Questions

I have a classifieds website. In the main page (index) I have several form
I have a classifieds website. In every classified, there is a back link which
I have a classifieds website, and on each classified there is a tip-form where
I have a classifieds website, and on each classifieds page, there is a form
I have a classifieds website, which uses PHP and MYSQL. I have several pages
I have a classifieds website where users must fill in a form in order
I have a classifieds website, and in the index.html there is a form. This
I have a classifieds website, and anybody may view the classifieds which people post.
I have a classifieds website which uses SOLR to search for whatever ads the
I have a classifieds website which I am now trying to integrate SOLR into,

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.