Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- userId | username | password
- ----------------------------
- 1 | example | temp1
- public function checkPasswordCorrect($username, $password) { // Returns true is the entered password is correct and false if it isn't.
- // This creates a mysqli context to run the connection through.
- $mysqli = new mysqli($this->dbHost, $this->dbUsername, $this->dbPassword, $this->dbPlusPlus);
- // If there is an error connecting to the database, it will be printed and the process will close.
- if (mysqli_connect_errno()) {
- printf("Connect failed: %sn", mysqli_connect_error());
- exit();
- }
- $sql = "SELECT password FROM users WHERE username='$username'";
- $result = $mysqli->query($sql);
- $row = $result->fetch_array(MYSQLI_ASSOC);
- $hashedPassword = $row["password"];
- $mysqli->close();
- echo $password."<br>".$hashedPassword."<br>"; // The input is correct and the hash matches that in the table.
- // We return a value of true or false, depending on the outcome of the verification.
- if(password_verify($password, $hashedPassword)) {
- echo "return true";
- return true;
- }
- else {
- echo "return false";
- return false;
- }
- }
- temp0022
- $2y$10$9TgjJzSaqOB
- return false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement