-
-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
password.texy translated in english (#500)
- Loading branch information
1 parent
9989306
commit 5d366de
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
\-- |