Ejemplo n.º 1
0
 public function editpasswordAction()
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $identity = $auth->getIdentity();
         $id = $identity->id;
         $email = $identity->emailaddress;
         $employeid = $identity->employeeId;
     }
     $password = trim($this->_request->getParam('password'));
     $newpassword = trim($this->_request->getParam('newpassword'));
     $confpassword = trim($this->_request->getParam('passwordagain'));
     $password = preg_replace('/\\s+/', ' ', $password);
     $newpassword = preg_replace('/\\s+/', ' ', $newpassword);
     $confpassword = preg_replace('/\\s+/', ' ', $confpassword);
     $pwd = md5($password);
     $newpwd = md5($newpassword);
     $confpwd = md5($confpassword);
     $loginmodel = new Default_Model_Users();
     $userpassword = $loginmodel->getLoggedInUserPwd($id, $email, $employeid);
     $sespwd = $userpassword['emppassword'];
     $changepasswordform = new Default_Form_changepassword();
     $sitepreferencemodel = new Default_Model_Sitepreference();
     $sitepreferenceArr = $sitepreferencemodel->SitePreferanceData();
     /*
         Pattern Used for alphanumeric expression 
     	   'pattern'=> '/^(?=.*[0-9])(?=.*[a-zA-Z])([a-zA-Z0-9]+)$/',
     		  -> Here the first bracket() inside the pattern specifies that atleast one number should be there in the expression.
     		  -> Second bracket() specifies that atleast one alphabet should be present in the expression.
     		  -> Third bracket() specifies the allowed set of characters in the expression.
     		  
     	Pattern Used for alphanumeric and special characters 
     	    'pattern'=> '/^(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[.\-#$@&\_*])([a-zA-Z0-9.\-#$@&\_*]+)$/',
     		  -> Here the first bracket() inside the pattern specifies that atleast one number should be there in the expression.
     		  -> Second bracket() specifies that atleast one alphabet should be present in the expression.
     		  -> Third bracket() specifies that atleast one special character should be present in the expression.
     		  -> Fourth bracket() specifies the allowed set of characters in the expression.
     
                 Pattern Used for numbers and special characters 
     	    'pattern'=> '/^(?=.*[0-9])(?=.*[.\-#$@&\_*])([0-9.\-#$@&\_*]+)$/',
     		  -> Here the first bracket() inside the pattern specifies that atleast one number should be there in the expression.
     		  -> Second bracket() specifies that atleast one special character should be present in the expression.
     		  -> Third bracket() specifies the allowed set of characters in the expression.				  
     */
     if (!empty($sitepreferenceArr)) {
         if ($sitepreferenceArr[0]['passwordid'] == 1) {
             $changepasswordform->newpassword->addValidator("regex", true, array('pattern' => '/^(?=.*[0-9])(?=.*[a-zA-Z])([a-zA-Z0-9]+)$/', 'messages' => array('regexNotMatch' => 'Please enter only alphanumeric characters.')));
             $changepasswordform->passwordagain->addValidator("regex", true, array('pattern' => '/^(?=.*[0-9])(?=.*[a-zA-Z])([a-zA-Z0-9]+)$/', 'messages' => array('regexNotMatch' => 'Please enter only alphanumeric characters.')));
         } else {
             if ($sitepreferenceArr[0]['passwordid'] == 2) {
                 $changepasswordform->newpassword->addValidator("regex", true, array('pattern' => '/^(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[.\\-#$@&\\_*])([a-zA-Z0-9.\\-#$@&\\_*]+)$/', 'messages' => array('regexNotMatch' => 'Please enter only characters,numbers and special characters.')));
                 $changepasswordform->passwordagain->addValidator("regex", true, array('pattern' => '/^(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[.\\-#$@&\\_*])([a-zA-Z0-9.\\-#$@&\\_*]+)$/', 'messages' => array('regexNotMatch' => 'Please enter only characters,numbers and special characters.')));
             } else {
                 if ($sitepreferenceArr[0]['passwordid'] == 3) {
                     $changepasswordform->newpassword->addValidator("regex", true, array('pattern' => '/^[0-9]+$/', 'messages' => array('regexNotMatch' => 'Please enter numbers only.')));
                     $changepasswordform->passwordagain->addValidator("regex", true, array('pattern' => '/^[0-9]+$/', 'messages' => array('regexNotMatch' => 'Please enter numbers only.')));
                 } else {
                     $changepasswordform->newpassword->addValidator("regex", true, array('pattern' => '/^(?=.*[0-9])(?=.*[.\\-#$@&\\_*])([0-9.\\-#$@&\\_*]+)$/', 'messages' => array('regexNotMatch' => 'Please enter only numbers and special characters.')));
                     $changepasswordform->passwordagain->addValidator("regex", true, array('pattern' => '/^(?=.*[0-9])(?=.*[.\\-#$@&\\_*])([0-9.\\-#$@&\\_*]+)$/', 'messages' => array('regexNotMatch' => 'Please enter only numbers and special characters.')));
                 }
             }
         }
     } else {
         $changepasswordform->newpassword->addValidator("regex", true, array('pattern' => '/^(?=.*[0-9])(?=.*[a-zA-Z])([a-zA-Z0-9]+)$/', 'messages' => array('regexNotMatch' => 'Please enter only alphanumeric characters.')));
         $changepasswordform->passwordagain->addValidator("regex", true, array('pattern' => '/^(?=.*[0-9])(?=.*[a-zA-Z])([a-zA-Z0-9]+)$/', 'messages' => array('regexNotMatch' => 'Please enter only alphanumeric characters.')));
     }
     /* Logic ends for site preference password validation
           END
        */
     if ($this->getRequest()->getPost()) {
         if ($changepasswordform->isValid($this->_request->getPost()) && $sespwd == $pwd && $newpwd == $confpwd && $pwd != $newpwd) {
             $loginmodel->editadminPassword($newpwd, $id, $email, $employeid);
             $this->_helper->json(array('result' => 'saved', 'message' => "Password changed successfully."));
         } else {
             $messages = $changepasswordform->getMessages();
             if ($sespwd != $pwd && $password != '') {
                 $messages['password'] = array('Wrong password. Please enter correct password.');
             }
             if ($newpwd != $confpwd && $newpassword != '' && $confpassword != '') {
                 $messages['passwordagain'] = array('New password and confirm password did not match.');
             }
             if ($pwd == $newpwd && $newpassword != '' && $password != '') {
                 $messages['passwordagain'] = array('Please choose a different password.');
             }
             $messages['result'] = 'error';
             $this->_helper->json($messages);
         }
     }
 }