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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:01:24+00:00 2026-06-09T18:01:24+00:00

Crypt is generating different hashes with the same input data, and the [following] previously

  • 0

Crypt is generating different hashes with the same input data, and the [following] previously functional hash generator/check is no longer working for authenticating users:

public static function blowfish($password, $storedpass = false) {
    //if encrypted data is passed, check it against input ($info) 
      if ($storedpass) { 
            if (substr($storedpass, 0, 60) == crypt($password, "$2y$08$".substr($storedpass, 60))) { 
                return true; 
            }  else { 
                return false; 
            } 
      }  else { 
          //make a salt and hash it with input, and add salt to end 
          $salt = ""; 
          for ($i = 0; $i < 22; $i++) { 
            $salt .= substr("./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", mt_rand(0, 63), 1); 
          } 
          //return 82 char string (60 char hash & 22 char salt) 
          return crypt($password, "$2y$08$".$salt).$salt; 
     }
}

I’m banging my head against the wall and have found no answers in differences between Zend’s internal algorithms vs PHP vs operating system algorithms; or variations between PHP 5.3.8 vs earlier…

EDIT: My question is technically answered, and it is my fault I didn’t ask properly. I’ve implemented:

$salt = substr(bin2hex(openssl_random_pseudo_bytes(22)), 0, 22);
          //for ($i = 0; $i < 22; $i++) { 
            //$salt .= substr("./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", mt_rand(0, 63), 1); 
          //} 

My real question is; why are the following functions returning differently?

print(substr($storedpass, 0, 60)."<br />");

returns: $2y$08$43f053b1538df81054d4cOJyrO5/j7NtZBCw6LrFof29cLBs7giK6

print(crypt($password, "$2a$08$".substr($storedpass, 60)));

returns: $2a$08$43f053b1538df81054d4cOPSGh/LMc0PZx6RC6PlXOSc61BKq/F6.

  • 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-09T18:01:25+00:00Added an answer on June 9, 2026 at 6:01 pm

    Because you are creating the salt with the help of random numbers,

    The function mt_rand() will create random number each time when you are calling, optionally with min, max parameters. Usually for strong cryptography password hashing, Salt should be generated using a Cryptographically Secure Pseudo-Random Number Generator (CSPRNG).

    Then come to your problem, i assume there will be no difference in algorithm between ZEND and php. Because zend is a framework wrapping around the core php, and make use of it.

    To verify the password, how the crypt check work is

    crypt($password, $stored_hash) == $stored_hash;
    

    Once you stored the hash when you hash first, it will be easy to verify by this.

    That is what actually happens here, if you pass the hash as second parameter to the function blowfish, it will return the verification by a bool value, regardless of the salt.

    if (substr($storedpass, 0, 60) == crypt($password, "$2y$08$".substr($storedpass, 60))) { 
        return true; 
    }  else { 
        return false; 
    }
    

    for your information about hashing and security read this

    Hope this helps

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

Sidebar

Related Questions

1) How do you create secure Blowfish hashes of passwords with crypt()? $hash =
The following are both SHA256 hashes of an empty string, generated with PHP's crypt
Net::SSL is part of Crypt::SSLeay. While working on a bug report today, I was
I use a php script that hashes passwords using php's crypt and uses SHA512,
I'm generating data to send from a Ruby stack to a PHP stack. I'm
This question discusses encrypting data on the iPhone using the crypt() function. As an
I am learning programming abstract data types. Trying to build custom hash table based
Which hash algorithm does Ruby's String.crypt method use? When used in conjunction with a
I have used the crypt function in c to encrypt the given string. I
I am trying to use crypt() in PHP to authenticate users. Here is my

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.