我正在使用sha1函数将我的密码存储在mysql DB中..
$passwordHash = sha1($password);
从谷歌我得到了这个 来自用户注册
sha1( sha1(users_plaintext_password)+random string )
检查
server computes sha1( users_hashed_password_in_database +
$_SESSION['random_string'] )
if $_POST['password'] ==
sha1( users_hashed_password_in_database + $_SESSION['random_string'] )
我的问题是如何检查验证?这是正确的方法吗?并使用一些随机字符串作为盐给我的密码更多的保护??
答案 0 :(得分:1)
我会这样做:
$seed = 'some random string';
$passwordHash = sha1($password.$seed);
然后对用户输入的数据执行相同操作:
$pass = $_POST['password'];
if(sha1($pass.$seed) == $passwordHash){
//log user in
}
种子是一个好主意,因为用户经常选择容易猜到的密码。另一个优点是,如果有人设法破解他们的方式,您可以通过更改种子来恢复网站的安全性。