/** * {@inheritdoc} */ public function validatePassword(UserInterface $user, $password) { $hash = $user->getPassword(); // Check if the provided password is valid $isValid = Password::validate($password, $hash); // Check if the password needs to be rehashed IF the provided password is valid if ($isValid && Password::needsRehash($hash)) { $user->setPassword($password); $user->save(); } // Return validation result return $isValid; }
/** * */ public function testNeedsRehash() { $hash = Password::hash('foobar', 4); $this->assertFalse(Password::needsRehash($hash, 4)); $this->assertTrue(Password::needsRehash($hash, 5)); }