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
2/* User's password. */
3$password = 'my secret password';
4
5/* Secure password hash. */
6$hash = password_hash($password, PASSWORD_DEFAULT);
7
8
1
2<?php
3/**
4 * We just want to hash our password using the current DEFAULT algorithm.
5 * This is presently BCRYPT, and will produce a 60 character result.
6 *
7 * Beware that DEFAULT may change over time, so you would want to prepare
8 * By allowing your storage to expand past 60 characters (255 would be good)
9 */
10echo password_hash("rasmuslerdorf", PASSWORD_DEFAULT);
11?>
12
13
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 * We just want to hash our password using the current DEFAULT algorithm.
5 * This is presently BCRYPT, and will produce a 60 character result.
6 *
7 * Beware that DEFAULT may change over time, so you would want to prepare
8 * By allowing your storage to expand past 60 characters (255 would be good)
9 * Other algorithms such as PASSWORD_BCRYPT and PASSWORD_ARGON2ID may be used
10 * instead of PASSWORD_DEFAULT
11 */
12echo password_hash("rasmuslerdorf", PASSWORD_DEFAULT);
13?>
14
15