MD5和CRYPT的密码处理是';没有按预期工作


Password handling with MD5 and CRYPT isn't working as expected

我想做的是不言自明的:我得到一个用户设置的"用户名"answers"密码",并尝试加密它

以下是我迄今为止所尝试的:

//Firstly i recieve user and pswd
$usua=SQLite3::escapeString($_POST['usuario']);
$psw=SQLite3::escapeString($_POST['psw']);
//Then i proceed to encrypt
$key = md5('firstWord');
$salt = md5('secondWord');
function hashword($string,$salt){
    $string= crypt($string, '$1$'.$salt.'$');    
}
$psw = hashword($psw, $salt);

这段代码总是返回相同的结果:"$1$7b77d82"。

怎么了?

你会怎么做?

我应该使用Bcrypt吗?

显然,这个过程应该为每个使用的密码返回不同的值,但它没有。

对于用户名和密码的基本加密,您可以执行以下操作:

$usua=SQLite3::escapeString($_POST['usuario']);
$psw=SQLite3::escapeString($_POST['psw']);
$salt = "aString";
$encryptedUsr = crypt($usua, $salt);
$encryptedPsw = crypt($psw, $salt);

crypt(string $string, [string $salt])函数有两个参数:要加密的字符串和一个名为$salt的可选字符串,该字符串用于基于.