Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The PHP code is hashing <code>$pass</code> with the salt <code>$2a$07$xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxxxxx$</code> if <code>CRYPT_BLOWFISH</code> is set (<code>CRYPT_BLOWFISH == 1</code>). The salt has to follow the format indicated in the PHP documentation (<code>"$2a$", a two digit cost parameter, "$", and 22 digits from the alphabet "./0-9A-Za-z"</code>).</p> <p>I'm not sure if you can do it with the library you are referring, but you can use <code>bcrypt-ruby</code> instead.</p> <p>For your code it would be something like this, I'm using the same data from the PHP example ( <a href="http://php.net/manual/en/function.crypt.php" rel="nofollow">http://php.net/manual/en/function.crypt.php</a> ), I only take the 29 first characters of the salt because beyond that PHP ignores it:</p> <pre><code>require 'bcrypt-ruby' pass = "rasmuslerdorf" # Here you should put the $pass from your PHP code salt = '$2a$07$usesomesillystringfors' # Notice no $ at the end. Here goes your salt hashed_password = BCrypt::Engine.hash_secret(pass,salt) # =&gt; "$2a$07$usesomesillystringfore2uDLvp1Ii2e./U9C8sBjqp8I90dH6hi" </code></pre> <p>This gives you the same output as on the PHP example. If your salt is too long take the first 29 characters ($2a$07$ plus the next 22 extra characters).</p> <p>I tested the behavior of PHP, if the salt is too long (beyond 29 characters in total) the rest is ignored, if the salt is too short it will return 0. E.g in PHP:</p> <pre><code>&lt;?php crypt('rasmuslerdorf', '$2a$07$usesomesillystringforsalt$') // returns $2a$07$usesomesillystringfore2uDLvp1Ii2e./U9C8sBjqp8I90dH6hi crypt('rasmuslerdorf', '$2a$07$usesomesillystringfors') // returns $2a$07$usesomesillystringfore2uDLvp1Ii2e./U9C8sBjqp8I90dH6hi crypt('rasmuslerdorf', '$2a$07$usesomesilly') // returns 0 because the salt is not long enough ?&gt; </code></pre>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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