6
6
7
7
declare (strict_types=1 );
8
8
9
+ use Nette \Security \Passwords ;
9
10
use Nette \Security \SimpleAuthenticator ;
10
11
use Tester \Assert ;
11
12
@@ -14,16 +15,12 @@ require __DIR__ . '/../bootstrap.php';
14
15
15
16
16
17
$ users = [
17
- 'john ' => 'password123! ' ,
18
+ 'john ' => '$2a$12$dliX6LynG/iChDUF7DhKzulN7d3nU.l3/RozE1MmEaxxBWdZXppm2 ' ,
18
19
'admin ' => 'admin ' ,
19
20
];
20
21
21
22
$ authenticator = new SimpleAuthenticator ($ users );
22
23
23
- $ identity = $ authenticator ->authenticate ('john ' , 'password123! ' );
24
- Assert::type (Nette \Security \IIdentity::class, $ identity );
25
- Assert::equal ('john ' , $ identity ->getId ());
26
-
27
24
$ identity = $ authenticator ->authenticate ('admin ' , 'admin ' );
28
25
Assert::type (Nette \Security \IIdentity::class, $ identity );
29
26
Assert::equal ('admin ' , $ identity ->getId ());
@@ -39,3 +36,16 @@ Assert::exception(
39
36
Nette \Security \AuthenticationException::class,
40
37
"User 'nobody' not found. " ,
41
38
);
39
+
40
+
41
+ $ authenticator = new SimpleAuthenticator ($ users , verifier: new Passwords );
42
+
43
+ $ identity = $ authenticator ->authenticate ('john ' , 'password123! ' );
44
+ Assert::type (Nette \Security \IIdentity::class, $ identity );
45
+ Assert::equal ('john ' , $ identity ->getId ());
46
+
47
+ Assert::exception (
48
+ fn () => $ authenticator ->authenticate ('john ' , $ users ['john ' ]),
49
+ Nette \Security \AuthenticationException::class,
50
+ 'Invalid password. ' ,
51
+ );
0 commit comments