Skip to content

Instantly share code, notes, and snippets.

@GabeStah
Created December 9, 2015 04:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GabeStah/b9dadf97058f01cd82f7 to your computer and use it in GitHub Desktop.
Save GabeStah/b9dadf97058f01cd82f7 to your computer and use it in GitHub Desktop.
Coding Dojo - PHP Best Practices - Password Hash Example
<?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