Skip to content

Commit 3a7da75

Browse files
committed
Add rehashing example
1 parent 659ef32 commit 3a7da75

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

README.md

+18
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,24 @@ if ($manager->verify('easy to remember, hard to guess', $hash, PasswordManagerIn
3636
}
3737
```
3838

39+
Library offers a way to check if password needs to be rehashed, usually after you successfully checked if password that user provided is correct one:
40+
41+
```php
42+
$manager = new PasswordManager('global salt, if needed');
43+
44+
$hash = $manager->hash('easy to remember, hard to guess');
45+
46+
if ($manager->verify($user_provided_password, $hash_from_storage, PasswordManagerInterface::HASHED_WITH_PHP)) {
47+
if ($manager->needsRehash($hash_from_storage, PasswordManagerInterface::HASHED_WITH_PHP)) {
48+
// Update hash in our data storage
49+
}
50+
51+
// Proceed with user authentication
52+
} else {
53+
print "Invalid password\n";
54+
}
55+
```
56+
3957
### Password Policy
4058

4159
All passwords are validated against password policies. By default, policy will accept any non-empty string:

0 commit comments

Comments
 (0)