Skip to content

Instantly share code, notes, and snippets.

@ianchanning
Created May 10, 2016 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ianchanning/b9e0c43c80c2ffb05220da2ceeca9e60 to your computer and use it in GitHub Desktop.
Save ianchanning/b9e0c43c80c2ffb05220da2ceeca9e60 to your computer and use it in GitHub Desktop.
function login($username, $password) {
$options = array('cost' => 10);
$userdata = 'query to find the user in your framework/PDO prepared query';
$plainText = $password;
if ($userdata['legacy']) {
$password = md5($password);
}
if (!password_verify($password, $userdata['password'])) {
return false; // or a not-authorised error or whatever.
}
if ($user['legacy'] || password_needs_rehash($userdata['password'], PASSWORD_DEFAULT, $options)) {
$hash = password_hash($plainText, PASSWORD_DEFAULT, $options);
// store $hash in the password field
// set the legacy value to 0
}
return true; //or an authorised flag, etc
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment