66
77declare (strict_types=1 );
88
9+ use  Nette \Security \Passwords ;
910use  Nette \Security \SimpleAuthenticator ;
1011use  Tester \Assert ;
1112
@@ -14,16 +15,12 @@ require __DIR__ . '/../bootstrap.php';
1415
1516
1617$ users  = [
17- 	'john '  => 'password123! ' ,
18+ 	'john '  => '$2a$12$dliX6LynG/iChDUF7DhKzulN7d3nU.l3/RozE1MmEaxxBWdZXppm2 ' ,
1819	'admin '  => 'admin ' ,
1920];
2021
2122$ authenticator  = new  SimpleAuthenticator ($ users );
2223
23- $ identity  = $ authenticator ->authenticate ('john ' , 'password123! ' );
24- Assert::type (Nette \Security \IIdentity::class, $ identity );
25- Assert::equal ('john ' , $ identity ->getId ());
26- 
2724$ identity  = $ authenticator ->authenticate ('admin ' , 'admin ' );
2825Assert::type (Nette \Security \IIdentity::class, $ identity );
2926Assert::equal ('admin ' , $ identity ->getId ());
@@ -39,3 +36,16 @@ Assert::exception(
3936	Nette \Security \AuthenticationException::class,
4037	"User 'nobody' not found. " ,
4138);
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