PHP password_verify返回true,但不会返回false

时间:2018-06-25 20:23:47

标签: php passwords password-encryption

当密码输入与哈希密码匹配时,password_verify返回“ 1”,但是当密码输入不匹配时,password_verify不返回任何值。

$sql = "SELECT ID, Username, Password FROM UserLogin";
$result = $connect->query($sql);

for($x = 0; $x < $result->num_rows; $x++){
  //echo '<br>' . $x . '<br>' . mysqli_num_fields($result) . '<br>';

  $UsernameInput = $_POST['username'];
  $PasswordInput = $_POST['password'];

  //fetch row
  $row = $result->fetch_assoc();
  $Username = $row["Username"];
  $HashedPassword = $row["Password"];
  //password_verify(passwordtocheck,hashedpasswordtocheckagainst)
  $Password = password_verify($PasswordInput, $HashedPassword);
  echo $Username . ' ' . $HashedPassword . '<br>' . $Password . '<br>';
  if($UsernameInput == $Username && $PasswordInput == $Password){
    echo 'Login successful';
  }  
}

HTML:

<form method="post">
  Username: <input type='text' name='username'><br>
  <span><?php echo $usernameError ?></span><br>
  Password: <input type='password' name='password'><br>
  <span><?php echo $passwordError?></span><br>
  <input type="submit" name='submit' value="Submit">
</form>

0 个答案:

没有答案