我的注册页面上的代码:
$p_salt = rand_string(20);
$site_salt="subinsblogsalt"; /*Common Salt used for password storing on site.*/
$salted_hash = hash('sha256', $password.$site_salt.$p_salt);然后,我将盐连同加盐的密码一起插入到数据库中,但当我在登录页面上执行此操作时:
if(isset($_POST) && $email!='' && $password!=''){
$sql=$dbh->prepare("SELECT id,password,psalt FROM user WHERE email='".$email."'");
$sql->execute(array($email));
while($r=$sql->fetch()){
$p=$r['password'];
$p_salt=$r['psalt'];
$id=$r['id'];
}
$site_salt="subinsblogsalt";/*Common Salt used for password storing on site. You can't change it. If you want to change it, change it when you register a user.*/
$salted_hash = hash('sha256', $password.$site_salt.$p_salt);但它们根本不匹配,我回显了加了盐的散列,将其与数据库中的散列进行了比较,但它们是不同的。
发布于 2014-12-09 07:45:18
您将使用以下命令创建和存储密码:
$salted_hash = hash('sha256', $password.$site_salt.$p_salt);但是,当您从表中恢复密码时,您是在加密以比较已经加密的密码。
在比较密码时,请使用$p_salt。
https://stackoverflow.com/questions/27367941
复制相似问题