parser

Написать ответ на текущее сообщение

 

 
   команды управления поиском

php

AK666 17.11 18:15

<?php

$passwordHashCost = 13;

$password = "passwd";
echo "Password: ";
$password = trim(fgets(STDIN)," \n\r\t\v\x00");

$cost = 13;

function generateSalt($cost = 13)
{
  $cost = (int) $cost;
  if ($cost < 4 || $cost > 31) {
    echo 'Cost must be between 4 and 31.';
    trow;
  }
  $rand = "123456789a123456789b"; // 20-byte random string
  $salt = sprintf("$2y$%02d$", $cost); // Blowfish (bcrypt) prefix
  $salt .= str_replace('+', '.', substr(base64_encode($rand), 0, 22));
  return $salt;
}

$salt = generateSalt($cost);
$hash = crypt($password, $salt);

echo $hash;
echo " ";
echo $password;

echo " ";
if (password_verify($password, $hash)) {
    echo "pass";
} else {
    echo "fail";
}
?>
ak666@sGl:~$ php passwd.php
Password: TESTtestTEST
$2y$13$MTIzNDU2Nzg5YTEyMzQ1NeQ2dB3UqiSsapPRgCNrWmwfP62CzJwDW TESTtestTEST pass
ak666@sGl:~$