@ 2016-10-16T01:49:57Z <?php
function getCryptedPassword($plaintext, $salt = '', $encryption = 'crypt-blowfish', $show_encrypt = false)
{
// mimic the getSalt function so we can use it in the example.
if ($salt)
{
$salt = substr(preg_replace('|^{crypt}|i', '', $salt), 0, 16);
}
else
{
if (function_exists('random_bytes'))
{
$salt = '$2$' . substr(md5(random_bytes(16)), 0, 12) . '$';
}
else
{
// Fake the salt result (a previously generated salt using https://github.com/paragonie/random_compat )
$salt = '$2$9936b047ea8b$';
}
}
// Encrypt the password.
switch ($encryption)
{
case 'plain':
return $plaintext;
case 'sha':
$encrypted = base64_encode(mhash(MHASH_SHA1, $plaintext));
return ($show_encrypt) ? '{SHA}' . $encrypted : $encrypted;
case 'crypt':
case 'crypt-des':
case 'crypt-md5':
case 'crypt-blowfish':
return ($show_encrypt ? '{crypt}' : '') . crypt($plaintext, $salt);
case 'md5-hex':
default:
$encrypted = ($salt) ? md5($plaintext . $salt) : md5($plaintext);
return ($show_encrypt) ? '{MD5}' . $encrypted : $encrypted;
}
}
$plaintext = 'mySuperSecretPassword';
if (function_exists('random_bytes'))
{
$salt = '$2$' . substr(md5(random_bytes(16)), 0, 12) . '$';
//$salt = '$2y$09$anexampl$';
}
else
{
// Fake the salt result (a randomly created salt using https://github.com/paragonie/random_compat )
// $salt = '$2$9936b047ea8b$';
$salt = '$2y$09$anexampl$';
}
echo 'salt length = ' . strlen($salt) . "\n";
echo strlen(crypt($plaintext, $salt)) . "\n";
echo crypt('U*U', '$2a$CCCCCCCCCCCCCCCCCCCCC.E5YPO9kmyuRGyh0XouQYb4YMJKvyOeW') . "\n";
echo crypt($plaintext, $salt) . "\n";
echo strlen(getCryptedPassword($plaintext, $salt, 'crypt-blowfish')) . "\n";
echo getCryptedPassword($plaintext, $salt, 'crypt-blowfish');
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 7.0.0 - 7.0.20 , 7.1.0 - 7.1.25 , 7.2.0 - 7.2.13 , 7.3.0 - 7.3.1 salt length = 16
Deprecated: crypt(): Supplied salt is not valid for DES. Possible bug in provided salt format. in /in/Is24j on line 55
13
*0
Deprecated: crypt(): Supplied salt is not valid for DES. Possible bug in provided salt format. in /in/Is24j on line 57
$2xzaiMREaf7o
Deprecated: crypt(): Supplied salt is not valid for DES. Possible bug in provided salt format. in /in/Is24j on line 33
13
Deprecated: crypt(): Supplied salt is not valid for DES. Possible bug in provided salt format. in /in/Is24j on line 33
$2xzaiMREaf7o Output for 5.6.0 - 5.6.26 salt length = 16
16
$2SHYF.wPGyfE
$2y$09$anexampl$
16
$2y$09$anexampl$ preferences:dark mode live preview
45.95 ms | 407 KiB | 5 Q