@@ -30,9 +30,9 @@ class Pbkdf2PasswordEncoder extends BasePasswordEncoder
30
30
{
31
31
private $ algorithm ;
32
32
private $ encodeHashAsBase64 ;
33
- private $ iterations ;
33
+ private $ iterations = 1 ;
34
34
private $ length ;
35
- private $ encodedLength ;
35
+ private $ encodedLength = - 1 ;
36
36
37
37
/**
38
38
* @param string $algorithm The digest algorithm to use
@@ -44,9 +44,15 @@ public function __construct(string $algorithm = 'sha512', bool $encodeHashAsBase
44
44
{
45
45
$ this ->algorithm = $ algorithm ;
46
46
$ this ->encodeHashAsBase64 = $ encodeHashAsBase64 ;
47
- $ this ->iterations = $ iterations ;
48
47
$ this ->length = $ length ;
49
- $ this ->encodedLength = $ encodeHashAsBase64 ? intdiv ($ length + 2 , 3 ) << 2 : ($ length << 1 );
48
+
49
+ try {
50
+ $ this ->encodedLength = \strlen ($ this ->encodePassword ('' , 'salt ' ));
51
+ } catch (\LogicException $ e ) {
52
+ // ignore algorithm not supported
53
+ }
54
+
55
+ $ this ->iterations = $ iterations ;
50
56
}
51
57
52
58
/**
@@ -74,7 +80,7 @@ public function encodePassword($raw, $salt)
74
80
*/
75
81
public function isPasswordValid ($ encoded , $ raw , $ salt )
76
82
{
77
- if (( 0 < $ this -> length && \strlen ($ encoded ) !== $ this ->encodedLength ) || false !== strpos ($ encoded , '$ ' )) {
83
+ if (\strlen ($ encoded ) !== $ this ->encodedLength || false !== strpos ($ encoded , '$ ' )) {
78
84
return false ;
79
85
}
80
86
0 commit comments