Advertisement
Guest User

Untitled

a guest
Aug 25th, 2017
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. userId | username | password
  2. ----------------------------
  3. 1 | example | temp1
  4.  
  5. public function checkPasswordCorrect($username, $password) { // Returns true is the entered password is correct and false if it isn't.
  6.  
  7. // This creates a mysqli context to run the connection through.
  8. $mysqli = new mysqli($this->dbHost, $this->dbUsername, $this->dbPassword, $this->dbPlusPlus);
  9.  
  10. // If there is an error connecting to the database, it will be printed and the process will close.
  11. if (mysqli_connect_errno()) {
  12. printf("Connect failed: %sn", mysqli_connect_error());
  13. exit();
  14. }
  15.  
  16. $sql = "SELECT password FROM users WHERE username='$username'";
  17. $result = $mysqli->query($sql);
  18. $row = $result->fetch_array(MYSQLI_ASSOC);
  19.  
  20. $hashedPassword = $row["password"];
  21.  
  22. $mysqli->close();
  23.  
  24. echo $password."<br>".$hashedPassword."<br>"; // The input is correct and the hash matches that in the table.
  25.  
  26. // We return a value of true or false, depending on the outcome of the verification.
  27. if(password_verify($password, $hashedPassword)) {
  28. echo "return true";
  29. return true;
  30. }
  31. else {
  32. echo "return false";
  33. return false;
  34. }
  35. }
  36.  
  37. temp0022
  38. $2y$10$9TgjJzSaqOB
  39. return false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement