[英]password_verify does not work
Hi I've got a problème with my verif password (PHP-7). 嗨,我有一个用Verif密码(PHP-7)的问题。
this is my code: 这是我的代码:
if(isset($_POST['change_pass'])){
global $conn;
$id = '1';
$pass = password_hash($_POST['pass'], PASSWORD_DEFAULT);
$conf_pass = $_POST['conf_pass'];
$verif_pass = $_POST['verif_pass'];
$query = $conn->query("SELECT * FROM bdd WHERE id='$id'");
$data = $query->fetch(PDO::FETCH_ASSOC);
if(!empty($pass) && !empty($conf_pass) && !empty($verif_pass)){
if(password_verify($conf_pass, $pass)){
if($pass == $conf_pass){
$update = $conn->query("UPDATE bdd SET password='$pass' WHERE id='$id'");
if($update){
echo 'Mot de passe changé';
}else{
echo 'Erreur SQL';
}
}else{
echo 'Les mots de passe ne correspondent pas'; var_dump(password_verify($conf_pass, $pass));
}
}else{
echo 'La confirmation du mot de passe actuelle est erronée';
}
}else{
echo 'Vous devez compléter tous les champs';
}
}
and the error message is that: Les mots de passe ne correspondent pasbool(true) 错误消息是: 通讯员pasbool(true)
someone see wat's wrong ? 有人看到扫管s错了吗?
Please re-read password_verify
documentation page . 请重新阅读password_verify
文档页面 。
password_verify
is not for confirmation of password. password_verify
不是用于确认密码。 It hashes the first argument(with salt) and compares it to the second argument: 它对第一个参数(用salt)进行哈希处理并将其与第二个参数进行比较:
bool password_verify ( string $password , string $hash )
$password
: Raw password $password
:原始密码
$hash
: Hashed password(usually queried from DB) $hash
:哈希密码(通常从数据库查询)
return value: whether password is correct or not. 返回值:密码是否正确。
NOTICE The hash
argument, must be calculated with password_hash
. 注意 hash
参数必须使用password_hash
计算。
You should use parameterize queries for all DB interactions involving user input. 您应该对所有涉及用户输入的数据库交互使用参数化查询。
The password_verify
takes parameter 1 as an plain text password and parameter 2 as the hashed value (usually the DB value). password_verify
将参数1作为纯文本密码,并将参数2作为哈希值(通常是DB值)。 So you need to change your usage of that function. 因此,您需要更改该功能的用法。 Hash it just for the storage. 哈希它只是为了存储。
$pass = $_POST['pass'];
$conf_pass = $_POST['conf_pass'];
$verif_pass = $_POST['verif_pass'];
$query = $conn->prepare("SELECT password FROM bdd WHERE id=?");
$query->execute(array($id));
$data = $query->fetch(PDO::FETCH_ASSOC);
if(!empty($pass) && !empty($conf_pass) && !empty($verif_pass)){
if(password_verify($pass, $data['password'])){
$update = $conn->query("UPDATE bdd SET password= ? WHERE id= ?");
$update->execute(array(password_hash($pass, PASSWORD_DEFAULT), $id));
Also if only selecting one column, use its name, not *
it will save you resources. 同样,如果仅选择一列,则使用其名称,而不是*
,它将节省资源。
All is done, 一切都完成了
I've got do a bad replace, this is the correct code: 我做了一个不好的替换,这是正确的代码:
if(!empty($pass) && !empty($conf_pass) && !empty($verif_pass)){
if($verif_pass == $data['password']){
if($conf_pass == $_POST['pass']){
$update = $conn->query("UPDATE hyona_ftelecom_web_users SET password='$pass', first_connect='1' WHERE phone='$phone'");
if($update){
notify('success','Succès','Votre mot de passe a bien été changer.');
}else{
notify('danger','Erreur','Erreur SQL.');
}
}else{
notify('warning','Attention','Les mots de passe ne correspondent pas.');
}
}else{
notify('warning','Attention','La confirmation du mot de passe actuelle est erronée.');
}
}else{
notify('warning','Attention','Vous devez compléter tous les champs.');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.