Skip to content

Simple PHP class to hash passwords using PBKDF2 and SHA256 in order to securely store them in a database.

License

Notifications You must be signed in to change notification settings

dinismadeira/php-password-hash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Simple PHP Password and Hash Generator

Simple PHP Class to store passwords as hashes in a database.

By default it uses pbkdf2 to iterate a sha256 hash with a random salt.

Usage

Get the hash for a password

// hash the password using sha256 iterated 2^10 times
$pass = new Pass($plainTextPass, 'sha256', 10);

// insert in the database
$query = "INSERT INTO users (user, password_algorithm, password_iterations, password_salt, password_hash) VALUES (
    '$user', '{$pass->getAlgo()}', {$pass->getIter()}, UNHEX('{$pass->getSalt()}'), UNHEX('{$pass->getHash()}')";

Authenticate a user

if (Pass::check($plainTextPass, $passwordAlgorithm, $passwordIterations, $passwordSalt, $passwordHash)) {
  // login successful
}

About

Simple PHP class to hash passwords using PBKDF2 and SHA256 in order to securely store them in a database.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages