2017-09-21 1 views
-7

Dans ma page de connexion, j'obtiens une erreur après password_verify où comme si j'utilisais hash_equals si je vérifiais le mot de passe. Besoin de connaître la raison.Pourquoi hash_equals et password_verify ne fonctionnent pas correctement?

le deuxième problème est chaque fois que je change le mot de passe en changeant la page de mot de passe hash_equals ne vérifie pas le mot de passe. ci-dessous sont les codes

if (!password_verify($password, $user['password'])) { 
    $errors[]='Password does not match'; 
} 

if (!hash_equals($password, $user['password'])) { 
    $errors[]='Password does not match'; 
} 
+2

Avez-vous lu le manuel à propos de ces deux fonctions? – Mjh

Répondre

0

La fonction hash_equals() ne vise pas à vérifier un mot de passe avec un hachage, qui est le travail de la fonction password_verify(), donc ne pas utiliser hash_equals() dans votre code:

// Hash a new password for storing in the database. 
// The function automatically generates a cryptographically safe salt. 
$hashToStoreInDb = password_hash($_POST['password'], PASSWORD_DEFAULT); 

// Check if the hash of the entered login password, matches the stored hash. 
// The salt and the cost factor will be extracted from $existingHashFromDb. 
$isPasswordCorrect = password_verify($_POST['password'], $existingHashFromDb);