public function ResetPassword()
 {
     $salt = $this->passwordEncryption->Salt();
     $encryptedPassword = $this->passwordEncryption->Encrypt($this->page->GetPassword(), $salt);
     $user = $this->userRepository->LoadById($this->page->GetUserId());
     $user->ChangePassword($encryptedPassword, $salt);
     $this->userRepository->Update($user);
 }
 public function testGeneratesSaltAndHashesPassword()
 {
     $password = '******';
     $encryption = new PasswordEncryption();
     $salt = $encryption->Salt();
     $actualEncryptedPassword = $encryption->Encrypt($password, $salt);
     $expectedEncryptedPassword = sha1($password . $salt);
     $this->assertEquals($expectedEncryptedPassword, $actualEncryptedPassword, "Password was not encrypted correctly");
 }
 public function testPasswordValidatorComparesStoredPasswordAgainstProvidedPassword()
 {
     $passwordEncryption = new PasswordEncryption();
     $salt = $passwordEncryption->Salt();
     $current = "some password";
     $user = new User();
     $encrypted = $passwordEncryption->Encrypt($current, $salt);
     $user->encryptedPassword = $encrypted;
     $user->passwordSalt = $salt;
     $validator = new PasswordValidator($current, $user);
     $validator->Validate();
     $this->assertTrue($validator->IsValid());
 }
 public function SendRandomPassword()
 {
     $emailAddress = $this->_page->GetEmailAddress();
     Log::Debug('Password reset request for email address %s requested from REMOTE_ADDR: %s REMOTE_HOST: %s', $emailAddress, $_SERVER['REMOTE_ADDR'], $_SERVER['REMOTE_HOST']);
     $temporaryPassword = Password::GenerateRandom();
     $passwordEncryption = new PasswordEncryption();
     $salt = $passwordEncryption->Salt();
     $encrypted = $passwordEncryption->Encrypt($temporaryPassword, $salt);
     $userRepository = new UserRepository();
     $user = $userRepository->FindByEmail($emailAddress);
     if ($user != null) {
         $user->ChangePassword($encrypted, $salt);
         $userRepository->Update($user);
         $emailMessage = new ForgotPasswordEmail($user, $temporaryPassword);
         ServiceLocator::GetEmailService()->Send($emailMessage);
     }
 }
Exemple #5
0
 public function Validate($salt)
 {
     $encrypted = $this->Encryption->Encrypt($this->plaintext, $salt);
     return $this->encrypted == $encrypted;
 }