Created
June 11, 2019 18:48
-
-
Save NicholasKimuli/b7e054d1184935f628a297574a53add3 to your computer and use it in GitHub Desktop.
Doorstep Password Hash Function -- depreciated from php7.0
This file contains hidden or 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
// 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