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

  • Home
  • SEARCH
  • 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 8978537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:38:17+00:00 2026-06-15T19:38:17+00:00

I created a registration and a login script which hash the password with salt

  • 0

I created a registration and a login script which hash the password with salt exactly the same way, however when the user attempts to login using their password, the hashed login password and the one stored in the database differ, it was working a couple of days ago and I haven’t changed anything in the login and registration scripts.

Here is what the stored credentials are

DBEMAIL: jd@gmail.com

DBPASSWORD:
addb18f27b6970082727069aa5853116223c5ab46f46a7b07340757804670aef61311ff0254ec45ea78d9ea6d8afb2cefdf3afd6bd4947f6fc558f46703fac1c

Here is what the User inserted credentials are:

UEMAIL: jd@gmail.com

UPASSWORD: 4123363f30664825356a238fe7a568910315e6f6aa8a57d0264844c641e856ab207200f4c75a532b2ebecdbd062bff31da101d973ab0f83eaefd2323a39a4a88

They are hashed using:

$salt   = "salinger";
$hashed = hash_hmac("sha512", $password, $salt);

The full registration function (it’s messy I know but it works (until now):

function registerUser($firstname, $surname, $email, $password, $secretQ, $secretA,    $address, $city, $postcode) {
    $flag = array();
    $validEmail = validateEmail($email);
    if (($validEmail) == true) {
         //Do not flag
    } else {
        array_push($flag, 1);
    }
    if ((textOnly("First name", $firstname) == true) || ((textOnly("Surname", $surname)) == true) || ((textOnly("City", $city)) == true)) {
        array_push($flag, 1);
    }
    if ((emptyField($firstname)) || (emptyField($surname)) || (emptyField($email)) || (emptyField($password)) || (emptyField($secretA)) || (emptyField($address)) || (emptyField($city)) || (emptyField($postcode))) {
        array_push($flag, 1);
    }
    if (validPostcode($postcode) == false) {
        array_push($flag, 1);
    }
    if (duplicateEmail($email) == true) {
        array_push($flag, 1);
    }
    if (validatePassword($password) == false) {
        array_push($flag, 1);
    } else {
        $password = validatePassword($password);
    }
    switch ($secretQ) {
        case 1:
            $secretQ = "Your mothers maiden name?";
            break;
        case 2:
            $secretQ = "Name of your first pet?";
            break;
        case 3:
            $secretQ = "The name of your high school?";
            break;
        case 4:
            $secretQ = "Your favourite instrument?";
            break;
    }

    $salt   = "salinger";
    $hashed = hash_hmac("sha512", $password, $salt);

    if (!empty($flag)) {
        echo "There are errors with your registration, go back and ammend it. <br /> <a href=\"register.php\">&lt;&lt; Back</a>";
    } else {
        if ((isset($firstname)) && (isset($surname)) && (isset($email)) && (isset($password)) && (isset($secretQ)) && (isset($secretA)) && (isset($address)) && (isset($city)) && (isset($postcode))) {
            $sql = "INSERT INTO customer (forename, surname, email, password, secretQ, secretA, address_street, address_city, address_postcode, member_type) VALUES ('$firstname', '$surname', '$email', '$hashed', '$secretQ', '$secretA', '$address', '$city', '$postcode', 'User');";
            header("Location: index.php");
        } else {
            array_push($flag, 1);
        }
    }
    $result = mysql_query($sql);
    if (!$result) {
        die(mysql_error());
    }
}

The login function:

function loginUser($email, $password) {
    if (validateEmail($email) == true) {
        $sql    = "SELECT customerid, forename, email, password, secretA, member_type FROM customer WHERE email = '$email'";

        $result = mysql_query($sql);

        while ($record = mysql_fetch_array($result)) {
            $DBid       = $record['customerid'];
            $DBemail    = $record['email'];
            $DBpassword = $record['password'];
            $DBforename = $record['forename'];
            $DBsecretA  = $record['secretA'];
            $DBmember   = $record['member_type'];
        }

        if (!$result) {
            die(mysql_error());
        }

        $salt   = "salinger";
        $hashed = hash_hmac("sha512", $password, $salt);

        echo "DBEMAIL: $DBemail   DBPASSWORD: $DBpassword <br/>";
        echo "UEMAIL: $email  UPASSWORD: $hashed <br/>";

        if (($email == $DBemail) && ($hashed == $DBpassword)) {
            $match = true;
        } else {
            $match = false;
        }

        if ($match == true) {
            session_start();
            $_SESSION['userid']   = $DBid;
            $_SESSION['Active']   = true;
            $_SESSION['forename'] = $DBforename;
            $_SESSION['type']     = $DBmember;
            header("Location: member.php");
        } else {
            echo "Incorrect credentials.";
        }
    } else {
        echo "Invalid email address!";
    }
return true;
}
  • 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-06-15T19:38:18+00:00Added an answer on June 15, 2026 at 7:38 pm

    In registerUser, I’d take a closer look at this:

    ...
    if (validatePassword($password) == false) {
        array_push($flag, 1);
    } else {
        $password = validatePassword($password);
    }
    ...
    

    $password will be overwritten, it appears, if it is a valid password. If all the passwords are the same in the database, then it’s likely that $password is being set to true, and that’s the value that’s salted. Depending on how you use validatePassword, you may be able to remove the else-clause, leaving this:

    ...
    if (validatePassword($password) == false) {
        array_push($flag, 1);
    }
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple login/user registration script that stores passwords using sha1 and
I have created a registration page using CI that works fine. However, I encoded
I have created a registration/login system for my members area. Once the user has
So, if a login/registration system is created, so that when the user logs in,
I have created a django app. It has got a user login/registration on the
I have created Login forms and registration forms for a website. The form is
I've created a login page and registration page and now I want to use
I am new to symfony. I have created a registration form using the code:
Building a simple login page. If the user types in a password and password
Hide Registration And Login Link When User Is Logged In? I am new at

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.