1// To hash the password, use
2password_hash("MySuperSafePassword!", PASSWORD_DEFAULT)
3
4// To compare hash with plain text, use
5password_verify("MySuperSafePassword!", $hashed_password)
1//hash password
2$pass = password_hash($password, PASSWORD_DEFAULT);
3
4//verify password
5password_verify($password, $hashed_password); // returns true
1//hash password
2$hashed_password = password_hash($password, PASSWORD_DEFAULT);
3
4//verify password
5password_verify($password, $hashed_password); // returns true
1
2<?php
3/**
4 * Note that the salt here is randomly generated.
5 * Never use a static salt or one that is not randomly generated.
6 *
7 * For the VAST majority of use-cases, let password_hash generate the salt randomly for you
8 */
9$options = [
10 'cost' => 11,
11 'salt' => mcrypt_create_iv(22, MCRYPT_DEV_URANDOM),
12];
13echo password_hash("rasmuslerdorf", PASSWORD_BCRYPT, $options)."\n";
14?>
15
16