Exemplo n.º 1
0
 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");
 }
Exemplo n.º 2
0
 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());
 }
Exemplo n.º 3
0
 public function Synchronize(AuthenticatedUser $user, $insertOnly = false)
 {
     if ($this->UserExists($user->UserName(), $user->Email())) {
         if ($insertOnly) {
             return;
         }
         $encryptedPassword = $this->_passwordEncryption->EncryptPassword($user->Password());
         $command = new UpdateUserFromLdapCommand($user->UserName(), $user->Email(), $user->FirstName(), $user->LastName(), $encryptedPassword->EncryptedPassword(), $encryptedPassword->Salt(), $user->Phone(), $user->Organization(), $user->Title());
         ServiceLocator::GetDatabase()->Execute($command);
     } else {
         $additionalFields = array('phone' => $user->Phone(), 'organization' => $user->Organization(), 'position' => $user->Title());
         $this->Register($user->UserName(), $user->Email(), $user->FirstName(), $user->LastName(), $user->Password(), $user->TimezoneName(), $user->LanguageCode(), Pages::DEFAULT_HOMEPAGE_ID, $additionalFields);
     }
 }
Exemplo n.º 4
0
 public function PageLoad()
 {
     if ($this->page->ResettingPassword()) {
         $this->LoadValidators();
         if ($this->page->IsValid()) {
             $user = $this->GetUser();
             $password = $this->page->GetPassword();
             $encrypted = $this->passwordEncryption->EncryptPassword($password);
             $user->ChangePassword($encrypted->EncryptedPassword(), $encrypted->Salt());
             $this->userRepository->Update($user);
             $this->page->ShowResetPasswordSuccess(true);
         }
     }
 }
Exemplo n.º 5
0
 public function PageLoad()
 {
     $this->page->SetAllowedActions(PluginManager::Instance()->LoadAuthentication());
     if ($this->page->ResettingPassword()) {
         $this->LoadValidators();
         if ($this->page->IsValid()) {
             $user = $this->GetUser();
             $password = $this->page->GetPassword();
             $encrypted = $this->passwordEncryption->EncryptPassword($password);
             $user->ChangePassword($encrypted->EncryptedPassword(), $encrypted->Salt());
             $this->userRepository->Update($user);
             $this->page->ShowResetPasswordSuccess(true);
         }
     }
 }
Exemplo n.º 6
0
 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);
     }
 }
Exemplo n.º 7
0
 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);
 }
Exemplo n.º 8
0
 public function Synchronize(AuthenticatedUser $user, $insertOnly = false)
 {
     if ($this->UserExists($user->UserName(), $user->Email())) {
         if ($insertOnly) {
             return;
         }
         $encryptedPassword = $this->_passwordEncryption->EncryptPassword($user->Password());
         $command = new UpdateUserFromLdapCommand($user->UserName(), $user->Email(), $user->FirstName(), $user->LastName(), $encryptedPassword->EncryptedPassword(), $encryptedPassword->Salt(), $user->Phone(), $user->Organization(), $user->Title());
         ServiceLocator::GetDatabase()->Execute($command);
         if ($user->GetGroups() != null) {
             $updatedUser = $this->_userRepository->LoadByUsername($user->Username());
             $updatedUser->ChangeGroups($user->GetGroups());
             $this->_userRepository->Update($updatedUser);
         }
     } else {
         $defaultHomePageId = Configuration::Instance()->GetKey(ConfigKeys::DEFAULT_HOMEPAGE, new IntConverter());
         $additionalFields = array('phone' => $user->Phone(), 'organization' => $user->Organization(), 'position' => $user->Title());
         $this->Register($user->UserName(), $user->Email(), $user->FirstName(), $user->LastName(), $user->Password(), $user->TimezoneName(), $user->LanguageCode(), empty($defaultHomePageId) ? Pages::DEFAULT_HOMEPAGE_ID : $defaultHomePageId, $additionalFields, array(), $user->GetGroups());
     }
 }
 public function testResetPasswordEncryptsAndUpdates()
 {
     $password = '******';
     $salt = 'salt';
     $encrypted = 'encrypted';
     $userId = 123;
     $this->page->expects($this->atLeastOnce())->method('GetUserId')->will($this->returnValue($userId));
     $this->page->expects($this->once())->method('GetPassword')->will($this->returnValue($password));
     $this->encryption->expects($this->once())->method('Salt')->will($this->returnValue($salt));
     $this->encryption->expects($this->once())->method('Encrypt')->with($this->equalTo($password), $this->equalTo($salt))->will($this->returnValue($encrypted));
     $user = new User();
     $this->userRepo->expects($this->once())->method('LoadById')->with($this->equalTo($userId))->will($this->returnValue($user));
     $this->userRepo->expects($this->once())->method('Update')->with($this->equalTo($user));
     $this->presenter->ResetPassword();
     $this->assertEquals($encrypted, $user->encryptedPassword);
     $this->assertEquals($salt, $user->passwordSalt);
 }
Exemplo n.º 10
0
 public function Validate($salt)
 {
     $encrypted = $this->Encryption->Encrypt($this->plaintext, $salt);
     return $this->encrypted == $encrypted;
 }