Last active
August 29, 2015 13:56
-
-
Save rotexdegba/9254781 to your computer and use it in GitHub Desktop.
PHP Password hashing demo.
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 | |
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