Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is crypt() returning different hashes with the same salt?
    primarykey
    data
    text
    <pre><code>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, "$2a$08$".substr($storedpass, 60))) { return true; } else { return false; } } else { //make a salt and hash it with input, and add salt to end $salt = "143cd669b02e155c3cca6e";//substr(bin2hex(openssl_random_pseudo_bytes(22)), 0, 22); //for ($i = 0; $i &lt; 22; $i++) { //$salt .= substr("./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", mt_rand(0, 63), 1); //} //return 82 char string (60 char hash &amp; 22 char salt) return crypt($password, "$2a$08$".$salt).$salt; } } print(substr($storedpass, 0, 60)."&lt;br /&gt;"); print(crypt($password, "$2a$08$".substr($storedpass, 60))."&lt;br /&gt;"); print(substr($storedpass, 60)); </code></pre> <p>Produces the result:</p> <pre><code>$2a$08$143cd669b02e155c3cca6eM3k8s9BdE4jErJXJ8wSxshJDPcJQVPW $2a$08$143cd669b02e155c3cca6eEiYm6ilW1ZC1PBS07LOh2XSq1NODSKK 143cd669b02e155c3cca6e </code></pre> <p>You can see I was previously generating a random salt of 22 characters, and I know all about PHPASS, that mt_rand() is not a CSPRNG, etc etc. What confuses/concerns me is simply why crypt() (given $password = 'admin') generates a different hash even using a static salt. You can see I've printed the substr($storedpass, 60) which generates the proper salt, but then running the crypt() function (with the same parameters to create the initial $storedpass) it generates a different result, breaking authentication for a (relatively small and not mission-critical) application of mine...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload