<?php
// generate random string given length
function genString($length = 22){
$s = '';
$chars = array_merge(range('A','Z'), range('a','z'), range(0,9));
while($length > 0){
$randKey = array_rand($chars, 1);
$s .= $chars[$randKey];
$length--;
}
return $s;
}
$prefix = (PHP_VERSION_ID >= 50307) ? '$2y$' : '$2a$';
$salt = $prefix.genString();
//echo 'Salt: '.$salt.'<br>';
$password = 'password';
$hash = crypt($password, $salt);
echo 'Strlen: '.strlen($hash).' ------ ';
if (crypt($password, $hash) == $hash) {
echo "Password verified!";
}
- 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
- Strlen: 2 ------
- Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.28
- Strlen: 13 ------ Password verified!
- Output for 5.2.7 - 5.2.17
Process exited with code 139.- Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.6
- Notice: Use of undefined constant PHP_VERSION_ID - assumed 'PHP_VERSION_ID' in /in/eHWrC on line 15
Process exited with code 139.
preferences:
145.35 ms | 402 KiB | 234 Q