Skip to content

Instantly share code, notes, and snippets.

@NicholasKimuli
Created June 11, 2019 18:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NicholasKimuli/b7e054d1184935f628a297574a53add3 to your computer and use it in GitHub Desktop.
Save NicholasKimuli/b7e054d1184935f628a297574a53add3 to your computer and use it in GitHub Desktop.
Doorstep Password Hash Function -- depreciated from php7.0
// Encrypting the password
$cost = 10;
$salt = strtr(base64_encode(mcrypt_create_iv(16, MCRYPT_DEV_URANDOM)), '+', '.');
$salt = sprintf("$2a$%02d$", $cost) . $salt;
$hash = crypt('User Input Password', $salt);
// Decrypting password
if(hash_equals('User Input Password', crypt('Hash stored in database', 'User Input password'))) {
// Password matches. Proceed.
} else {
// Password is incorrect
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment