-
-
Save GabeStah/b9dadf97058f01cd82f7 to your computer and use it in GitHub Desktop.
Coding Dojo - PHP Best Practices - Password Hash Example
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 | |
// Raw password, as entered by user. | |
$passwordOriginal = "LEd4P?qE5s"; | |
/* | |
* Hash the password using the PASSWORD_DEFAULT algorithm. | |
* Currently using the crypt() algorithm, but using PASSWORD_DEFAULT ensures future compatibility. | |
* Database tables should accommodate a length of 255 characters for $passwordHash values. | |
*/ | |
$passwordHash = password_hash($passwordOriginal, PASSWORD_DEFAULT); // Store in database. | |
// Verify a password against the hash stored in the database with password_verify(). | |
password_verify($passwordOriginal, $passwordHash); // True | |
password_verify("random password", $passwordHash); // False | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment