/** * It should detect already hashed passwords. * * @dataProvider providePreSaveAlreadyHashed */ public function testOnPreSavePasswordAlreadyHashed($hash) { $this->storageEvent->getContent()->willReturn($this->user->reveal()); $this->user->getPassword()->willReturn($hash); $this->passwordFactory->createHash(Argument::cetera())->shouldNotBeCalled(); $this->user->setPassword($hash)->shouldBeCalled(); $this->listener->onUserEntityPreSave($this->storageEvent->reveal()); }
/** * Hash user passwords on save. * * Hashstrength has a default of '10', don't allow less than '8'. * * @param Entity\Users $usersEntity */ protected function passwordHash(Entity\Users $usersEntity) { if ($usersEntity->getShadowSave()) { return; } elseif ($usersEntity->getPassword() && $usersEntity->getPassword() !== '**dontchange**') { $hasher = new PasswordHash($this->hashStrength, true); $usersEntity->setPassword($hasher->HashPassword($usersEntity->getPassword())); } else { unset($usersEntity->password); } }
/** * Hash user passwords on save. * * @param Entity\Users $usersEntity */ protected function passwordHash(Entity\Users $usersEntity) { if ($usersEntity->getShadowSave()) { return; } elseif ($usersEntity->getPassword() && $usersEntity->getPassword() !== '**dontchange**') { $crypt = new PasswordLib(); $usersEntity->setPassword($crypt->createPasswordHash($usersEntity->getPassword(), '$2a$', ['cost' => $this->hashStrength])); } else { unset($usersEntity->password); } }
/** * Hash user passwords on save. * * @param Entity\Users $usersEntity */ protected function passwordHash(Entity\Users $usersEntity) { if ($usersEntity->getPassword() !== null) { $usersEntity->setPassword($this->getValidHash($usersEntity->getPassword())); } }