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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:03:26+00:00 2026-06-02T05:03:26+00:00

I have two functions, HashPassword() and ValidatePassword . The first one hashes the password

  • 0

I have two functions, HashPassword() and ValidatePassword.

The first one hashes the password given on signup form with a dynamic salt and the second validates the password.

Basically, I am checking if the password hashes match they never do match. On my login form when I call the ValidatePassword() function I have tested echoing out the hashes in the ValidatePassword() to make sure I am splitting the hash in write place for comparing and I am but when comparing them, they echo out a different hash.

Probably easier to look at both functions to explain better.

<?php

// hashes a users password along with a dynamic salt
// dynamic salt is stored with users password and is seperated by a ;
function HashPassword($password){
    // creates a dynamic salt
    $DynamicSalt       = uniqid('', true);
    // hash the password given from user along with dynamic salt
    $HashedPassword    = hash('sha512', $password . $DynamicSalt);
    // combine the hashed password seperated by ; then the dynamic salt to store in database
    $final             = $HashedPassword.';'.$DynamicSalt; // this value is stored in database like: c29fc9e4acdd2962c4db3f108bee728cf015c8f6388ab2cd4f21e405f9d2f13b2d53a1ab8629aa21c3453906a98aff0d4b9a0e14bfc2c553a4f9c7c0c32fc58a;4f91cfc746b426.53641182
    return $final;
}

// validate password user entered ($password = password from user | $dbHashedPassword = hash from database)
function ValidatePassword($password, $dbHashedPassword){
    // we need to get the password hash before the salt, (fetch just the first 128 characters from database hash)
    $CorrectHash = substr($dbHashedPassword, 0, 128);
    // get the dynamic salt from end of sha512 hash (
    $DynamicSalt = substr($dbHashedPassword, 129, 151); // get just the dynamic salt part of the db hash
    // hash the password from user and the dynamic salt which we got from the end of the hash from database
    $TestHash    = hash('sha512', $password . $DynamicSalt);

    return ($CorrectHash == $TestHash);


    // WHEN I ECHO OUT THE THREE VARIABLES $CorrectHash, $DynamicSalt and $TestHash
    // THE $CorrectHash (from db, first 128 chars) is not the same as $TestHash
    // AND TO MAKE SURE I AM SPLITTING THE HASH AND DYNAMIC SALT InN THE CORRECT PLACE I ECHO OUT
    // $DynamicSalt and it is split in the correct place showing the 23 characters which the dynamic salt is 23 characters
    // BUT WHEN I COMBINE THE $password and $DynamicSalt in $TestHash it shows a completely different hash from the $CorrectHash (which we got and split from database)
}

?>

I’m not sure what’s wrong, but it seems I’m splitting the hash and dynamic salt in the correct place because when I echo out it shows the first 128 chars (sha512) then the dynamic salt (23 chars) but when echoing out the two 128 chars hashes they do not match (by this I mean they are completely different hashes).

  • 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-02T05:03:27+00:00Added an answer on June 2, 2026 at 5:03 am

    It’s probably something to do with how you’re splitting the hash you’re testing against. For instance, you’re trying to get a salt that’s 151 characters long.

    Try this:

    function ValidatePassword($password, $dbHashedPassword) {
        list($CorrectHash, $DynamicSalt) = explode(";",$dbHashedPassword,2);
        return $CorrectHash == hash("sha512",$password.$DynamicSalt);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two functions that make $.getJSON calls - one looks at JSON stored
I have two functions whose underlying logic is the same but in one case
I have two functions hooked on the submit event of a form. Each function
I have two functions, one which parses all the arguments sent to the function
I have two functions which one should i use? Please explain the difference. A:
I have two functions, one creates paragraphs dynamically and the other function selects (changes
I have two functions getCompanyDetails and getHostingDetails The first database getCompanyDetails works fine but
I have two functions written in VB.NET: 1) The first function (call it GetValues())
I have two functions named ChangeText() & ChangeColor(), the first function called ChangeText who
I have two functions to add and remove table rows that contain a form

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.