- crypt: documentation ( source)
- array_merge: documentation ( source)
- array_rand: documentation ( source)
- range: documentation ( source)
<?php
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;
}
$salt = '$2y$10$'.genString();
echo 'Salt: '.$salt.'<br>';
$password = '5adrftg';
$hash = crypt($password, $salt);
echo 'Hash: '.$hash.' -- Strlen: '.strlen($hash).'<br>';
//echo PHP_VERSION_ID.'<br>';
if (crypt($password, $hash) == $hash) {
echo "Password verified!";
}