Skip to content

Instantly share code, notes, and snippets.

Created Dec 9, 2015
What would you like to do?
Coding Dojo - PHP Best Practices - Password Hash Example
// 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