Created
May 20, 2015 18:51
-
-
Save ineentho/12a4bf88de1a7dd614f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$dbh = new PDO('mysql:host=localhost;dbname=test', 'root', 'sten123'); | |
function authenticate($username, $password) { | |
global $dbh; | |
$loginStmt = $dbh->prepare('SELECT password FROM users WHERE username = :username'); | |
$loginStmt->bindValue(':username', $username); | |
$loginStmt->execute(); | |
$row = $loginStmt->fetch(PDO::FETCH_ASSOC); | |
if (!$row) | |
return 'Account not found'; | |
if (!password_verify($password, $row['password'])) | |
return 'Incorrect password'; | |
return null; | |
} | |
$error = authenticate('Ineentho', 'sten123'); | |
if ($error) { | |
echo 'Could not login: ' . $error; | |
} else { | |
echo 'Logged in'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment