@@ -30,9 +30,9 @@ class Pbkdf2PasswordEncoder extends BasePasswordEncoder
3030{
3131 private $ algorithm ;
3232 private $ encodeHashAsBase64 ;
33- private $ iterations ;
33+ private $ iterations = 1 ;
3434 private $ length ;
35- private $ encodedLength ;
35+ private $ encodedLength = - 1 ;
3636
3737 /**
3838 * @param string $algorithm The digest algorithm to use
@@ -44,9 +44,15 @@ public function __construct(string $algorithm = 'sha512', bool $encodeHashAsBase
4444 {
4545 $ this ->algorithm = $ algorithm ;
4646 $ this ->encodeHashAsBase64 = $ encodeHashAsBase64 ;
47- $ this ->iterations = $ iterations ;
4847 $ 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 ;
5056 }
5157
5258 /**
@@ -74,7 +80,7 @@ public function encodePassword($raw, $salt)
7480 */
7581 public function isPasswordValid ($ encoded , $ raw , $ salt )
7682 {
77- if (( 0 < $ this -> length && \strlen ($ encoded ) !== $ this ->encodedLength ) || false !== strpos ($ encoded , '$ ' )) {
83+ if (\strlen ($ encoded ) !== $ this ->encodedLength || false !== strpos ($ encoded , '$ ' )) {
7884 return false ;
7985 }
8086
0 commit comments