Skip to content

Instantly share code, notes, and snippets.

@rotexdegba
Last active August 29, 2015 13:56
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 rotexdegba/9254781 to your computer and use it in GitHub Desktop.
Save rotexdegba/9254781 to your computer and use it in GitHub Desktop.
PHP Password hashing demo.
<?php
function register($user, $password) {
$hash = password_hash($password, PASSWORD_BCRYPT);
$this->store($user, $hash);
}
function login($user, $password) {
$hash = $this->fetchHash($user);
if (password_verify($password, $hash)) {
if (password_needs_rehash($hash, PASSWORD_BCRYPT)) {
$hash = password_hash($password, PASSWORD_BCRYPT);
$this->store($user, $hash);
}
$this->startSession();
return true;
}
return false;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment