Skip to content

Commit

Permalink
password.texy translated in english (#500)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasneubauer authored and dg committed Dec 27, 2021
1 parent 9989306 commit 5d366de
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions doc/en/passwords.texy
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
Working With Passwords - Nette\Security\Passwords
*************************************************

.[perex]
To manage security of our users, we never save their passwords in plaintext format, but we rather save the password´s fingerprint (eg. hash). There is no way to find out the real password from the password´s fingerprint. To create the fingerprint we have to use a save algorithm. Static class [Nette\Security\Passwords |api:] will help us with this.

Following examples expect this alias:

/--php
use Nette\Security\Passwords;
\--


hash($passwords, array $options = NULL)
=======================================

This method generates password´s hash using a modern bcrypt algorithm. We can set the `cost` parameter of range 4-31, which sets the number of iterations the algorithm takes to run. If we omit this parameter, a default value of `10` will be used.

.[warning]
The `cost` parameter is an exponent of function 2^n. If we set its value too high, the hash computation will take too long. By using the highest value of 31 the compuauion takes approximately 64 hours.

/--php
$hash = Passwords::hash($password); // Hashes the password
$hash = Passwords::hash($password, ['cost' => 12]); // Hashes the password using 12 iterations of bcrypt algorithm
\--

verify($password, $hash)
========================

This method finds out, if given password matches given fingerprint (hash).

/--php
if (Passwords::verify($password, $hash)) {
// This will run, if password matches the fingerprint (hash)
} else {
// This will run, if password does not match the fingerprint (hash)
}
\--

needsRehash($password, array $options = NULL)
=============================================

This method finds out, if the hash matches given options. We can set the `cost` parameter of range 4-31, which sets the number of iterations the algorithm takes to run. If we omit this parameter, a default value of `10` will be used.

/--php
if (Passwords::needsRehash($hash)) {
// This will run, if the password needs to be rehashed
}
\--

0 comments on commit 5d366de

Please sign in to comment.