function testChangingPassword()
 {
     $userB4 = $this->loginAsNormalUser();
     assertFalse(Passwords\isValid('n00p@ss', $userB4->passwordEncrypted));
     $this->get('/account/change-password');
     $this->submitForm($this->getForm('change-password-form'), array('current-password' => 'abc123', 'password' => 'n00p@ss', 'confirm-password' => 'n00p@ss'));
     $userAfter = User::loadFromID($userB4->id);
     assertTrue(Passwords\isValid('n00p@ss', $userAfter->passwordEncrypted));
 }
 function changePassword()
 {
     $user = $this->user;
     $form = new F\Form('post');
     $passwordField = F\newPasswordField('password', 'Password');
     $confirmPassField = new PasswordConfirmField('confirm-password', 'Re-enter password');
     $form->addSection('change-password', array(F\newPasswordField('current-password', 'Current Password')->required('Please authenticate by entering your current password.')->addValidation(function ($pass) use($user) {
         return Passwords\isValid($pass, $user->passwordEncrypted) ? array() : array("Your current password is incorrect!");
     }), $passwordField->addValidation(function ($pass) {
         return strlen($pass) < 5 ? array('Password must be at least five (5) characters long.') : array();
     }), $confirmPassField->required('Please confirm the password by entering it a second time.')));
     $success = false;
     if ($this->isPostRequestAndFormIsValid($form)) {
         $hashedPass = Passwords\hash($form->getValue("password"));
         $user->updatePassword($hashedPass);
         $success = true;
     }
     return $this->render('account/change-password.php', array('form' => $form, 'success' => $success, 'newPassword' => $this->takeFromSession('newPassword')));
 }