php - password_verify keeps returning false and I can't find answer anywhere -


password verify returns false. i've seen every answer here, none of helped. password field varchar(255). when var_dump password database, shows string(60) , password correct function still returns false. here code stores in database:

if(empty($_post['pass'])) {     $passerr = "password required!";     $errors[] = "pass error"; } else {     $pass = test_input($_post["pass"]);      if(!preg_match("/^(?=.*[a-za-z])(?=.*\d)[a-za-z\d]{8,}$/", $pass)) {         $passerr = "password not formed";         $errors[] = "pass error";     } else {         $pass_hashed = password_hash($pass, password_default);      } } $hash_ver = md5(rand(0, 1000)); $status = ""; $stm = $conn->prepare("insert user values(?, ?, ?, ?, ?, ?, ?, ?)");  $stm->bind_param("sssssssi", $id, $pass_hashed, $email, $fname, $lname, $hash_ver, $status, $id_role);  $stm->execute(); echo strlen($pass_hashed); 

and part of login script

if(count($array) != 0) {     echo "<script>alert('ima gresaka')</script>"; } else {      include('connectionfile/connection.php');       $stmt = $conn->prepare("select `name`,`last_name`,`status_verif`,`email`,`password` user `email`=?");     $stmt->bind_param("s", $email);     $stmt->execute();      if($res = $stmt->get_result()) {         $count = $res->num_rows;          if($count == 1) {              $row = $res->fetch_assoc();             $passwordb = $row['password'];              //echo "<p>".$passwordb."</p>";              $verify = password_verify($pass, $passwordb);              if($verify) {                 echo "<script>alert('password match')</script>";             } else {                 var_dump($verify);                 var_dump($passwordb);                 echo "<script>alert('password doesnt match')</script>";             }          } else {             echo "<script>alert('0 rows')</script>";         }      } else {         echo "<script>alert('no rows @ all')</script>";     }  } 

there two possible reasons. :

  • 1) $pass = test_input($_post["pass"]);

    the function test_input() $_post['pass'] string, unknown user. also, value of $pass not declared in second code block.

  • 2)

           $stm = $conn->prepare("insert user values(?, ?, ?, ?, ?,                             ?, ?, ?)");        $stm->bind_param("sssssssi", $id,$pass_hashed,         $email,$fname,$lname, $hash_ver,$status, $id_role); 

    the value inserting not inserted correct sql column or value extracting sql not correct column, maybe you're extracting , comparing md5 hash inserted?

it helpful if can show example output, such you'revar_dump values state.

it helpful show how $pass set in second code block test_input in first code block.

various parts of code improvement.

additionally, think logic structure -- if $pass doesn't fit preg_match? still inserted database. need catch these sorts of flow issues.

read how display php error logs, or better yet, dump them file read in ide.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -