You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 31, 2020. It is now read-only.
Copy file name to clipboardExpand all lines: docs/book/validators/undisclosed-password.md
+19-14
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,14 @@
1
1
# Undisclosed Password Validator
2
2
3
+
-**Since 2.13.0**
4
+
3
5
`Zend\Validator\UndisclosedPassword` allows you to validate if a given password was found in data breaches using the service [Have I Been Pwned?](https://www.haveibeenpwned.com), in a secure, anonymous way using [K-Anonymity](https://www.troyhunt.com/ive-just-launched-pwned-passwords-version-2) to ensure passwords are not send in full over the wire.
4
6
5
7
> ### Installation requirements
6
8
>
7
-
> This validator needs to make a request over HTTP, therefor it requires an HTTP client of your choice that implements[PSR-18](https://www.php-fig.org/psr/psr-18/) and [PSR-17](https://www.php-fig.org/psr/psr-17/) request and response factories.
9
+
> This validator needs to make a request over HTTP; therefore it requires an HTTP client. The validator provides support only for HTTP clients implementing[PSR-18](https://www.php-fig.org/psr/psr-18/) and [PSR-17](https://www.php-fig.org/psr/psr-17/) request and response factories.
8
10
>
9
-
> Make sure you have it installed before using this validator:
11
+
> To ensure you have these installed before using this validator, run the following:
10
12
>
11
13
> ```bash
12
14
> $ composer require psr/http-client
@@ -15,30 +17,33 @@
15
17
16
18
## Basic usage
17
19
18
-
To validate if a password was disclosed in a known data breach, you need to provide a HTTP Client that implements `Psr\Http\Client\ClientInterface`, a `Psr\Http\Message\RequestFactoryInterface` and a `Psr\Http\Message\ResponseFactoryInterface` to the constructor and validate the password you want to check.
20
+
The validator has three required constructor arguments:
21
+
22
+
- an HTTP Client that implements `Psr\Http\Client\ClientInterface`
23
+
- a `Psr\Http\Message\RequestFactoryInterface` instance
24
+
- a `Psr\Http\Message\ResponseFactoryInterface` instance
19
25
20
-
If the password was found via the service, `isValid` will return`false`. If the password was not found, `isValid` will return`true`.
26
+
Once you have an instance, you can then pass a password to its `isValid()` method to determine if it has been disclosed in a known data breach.
27
+
28
+
If the password was found via the service, `isValid()` will return`false`. If the password was not found, `isValid()` will return`true`.
21
29
22
30
```php
23
31
$validator = new Zend\Validator\UndisclosedPassword(
24
32
$httpClient, // a PSR-18 HttpClientInterface
25
33
$requestFactory, // a PSR-17 RequestFactoryInterface
26
34
$responseFactory // a PSR-17 ResponseFactoryInterface
27
35
);
28
-
```
29
-
```php
30
-
$result = $validator->isValid('password');
36
+
37
+
$result = $validator->isValid('password');
31
38
// $result is FALSE because "password" was found in a data breach
// $result is TRUE because "8aDk=XiW2E.77tLfuAcB" was not found in a data breach
37
42
```
38
43
39
44
## A simple command line example
40
45
41
-
In this example I'm using `zendframework/zend-diactoros` for HTTP messaging and `php-http/curl-client` as the HTTP client. Let's begin with installation of all required packages:
46
+
In this example, I'm using `zendframework/zend-diactoros` to provide HTTP messages, and `php-http/curl-client` as the HTTP client. Let's begin with installation of all required packages:
42
47
43
48
```bash
44
49
$ composer require \
@@ -47,10 +52,10 @@ $ composer require \
47
52
php-http/discovery \
48
53
php-http/curl-client \
49
54
zendframework/zend-diactoros \
50
-
zendframework/zend-validator
55
+
zendframework/zend-validator
51
56
```
52
57
53
-
Next thing is I create a file `undisclosed.php` where I will put inmy code.
58
+
Next, I create a file,`undisclosed.php`, where I put my code:
54
59
55
60
```php
56
61
<?php
@@ -74,13 +79,13 @@ echo 'Password "password" is ' . ($undisclosedPassword->isValid('password') ? 'n
74
79
echo'Password "NVt3MpvQ" is '. ($undisclosedPassword->isValid('NVt3MpvQ') ?'not disclosed':'disclosed') . PHP_EOL;
75
80
```
76
81
77
-
To run it, I use PHP on the command line:
82
+
To run it, I use the PHP command line interpreter:
0 commit comments