Example #1
0
 /**
  * Action FOR USERS to change the password of their mailbox.
  */
 public function changePasswordAction()
 {
     $form = new ViMbAdmin_Form_Mailbox_Password();
     if (isset($this->_options['defaults']['mailbox']['min_password_length'])) {
         $form->setMinPasswordLength($this->_options['defaults']['mailbox']['min_password_length']);
     }
     if ($this->getRequest()->isPost() && $form->isValid($_POST)) {
         $mailbox = $this->getD2EM()->getRepository('\\Entities\\Mailbox')->findOneBy(['username' => $form->getValue('username')]);
         if (!$mailbox) {
             $this->addMessage(_('Invalid username or password.'), OSS_Message::ERROR);
         } else {
             if (OSS_Auth_Password::verify($form->getValue('current_password'), $mailbox->getPassword(), ['pwhash' => $this->_options['defaults']['mailbox']['password_scheme'], 'pwsalt' => isset($this->_options['defaults']['mailbox']['password_salt']) ? $this->_options['defaults']['mailbox']['password_salt'] : null, 'pwdovecot' => isset($this->_options['defaults']['mailbox']['dovecot_pw_binary']) ? $this->_options['defaults']['mailbox']['dovecot_pw_binary'] : null, 'username' => $form->getValue('username')])) {
                 $mailbox->setPassword(OSS_Auth_Password::hash($form->getValue('new_password'), ['pwhash' => $this->_options['defaults']['mailbox']['password_scheme'], 'pwsalt' => isset($this->_options['defaults']['mailbox']['password_salt']) ? $this->_options['defaults']['mailbox']['password_salt'] : null, 'pwdovecot' => isset($this->_options['defaults']['mailbox']['dovecot_pw_binary']) ? $this->_options['defaults']['mailbox']['dovecot_pw_binary'] : null, 'username' => $form->getValue('username')]));
                 $this->getD2EM()->flush();
                 $this->addMessage(_('You have successfully changed your password.'), OSS_Message::SUCCESS);
                 $this->_redirect('auth/login');
             } else {
                 $this->addMessage(_('Invalid username or password.'), OSS_Message::ERROR);
             }
         }
     }
     $this->view->form = $form;
 }
Example #2
0
 /**
  * Action FOR USERS to change the password of their mailbox.
  */
 public function changePasswordAction()
 {
     $form = new ViMbAdmin_Form_Mailbox_Password();
     if ($this->getRequest()->isPost() && $form->isValid($_POST)) {
         $mailbox = Doctrine_Query::create()->from('Mailbox')->where('username = ?', $form->getValue('username'))->fetchOne();
         if (!$mailbox) {
             $this->addMessage(_('Invalid username or password.'), ViMbAdmin_Message::ERROR);
         } else {
             $cPassword = $mailbox['password'];
             if ($cPassword == $mailbox->hashPassword($this->_options['defaults']['mailbox']['password_scheme'], $form->getValue('current_password'), $this->_options['defaults']['mailbox']['password_hash'])) {
                 $mailbox->hashPassword($this->_options['defaults']['mailbox']['password_scheme'], $form->getValue('new_password'), $this->_options['defaults']['mailbox']['password_hash']);
                 $mailbox->save();
                 $this->addMessage(_('You have successfully changed your password.'), ViMbAdmin_Message::SUCCESS);
                 $this->_redirect('auth/login');
             } else {
                 $this->addMessage(_('Invalid username or password.'), ViMbAdmin_Message::ERROR);
             }
         }
     }
     $this->view->form = $form;
 }