checkPasswordPolicy() public static method

Checks whether a password matches some expected policy.
public static checkPasswordPolicy ( string $password, array $policy )
$password string A password.
$policy array A configuration with policy rules. Supported rules: - minLength: Minimum length of the password - maxLength: Maximum length of the password - maxSpace: Maximum number of white space characters The following are the types of characters required in a password. Either specific characters, character classes, or both can be required. Specific types are: - minUpper: Minimum number of uppercase characters - minLower: Minimum number of lowercase characters - minNumeric: Minimum number of numeric characters (0-9) - minAlphaNum: Minimum number of alphanumeric characters - minAlpha: Minimum number of alphabetic characters - minSymbol: Minimum number of punctuation / symbol characters - minNonAlpha: Minimum number of non-alphabetic characters Alternatively (or in addition to), the minimum number of character classes can be configured by setting the following. The valid range is 0 through 4 character classes may be required for a password. The classes are: 'upper', 'lower', 'number', and 'symbol'. For example: A password of 'p@ssw0rd' satisfies three classes ('number', 'lower', and 'symbol'), while 'passw0rd' only satisfies two classes ('lower' and 'number'). - minClasses: Minimum number (0 through 4) of character classes.
示例#1
0
 /**
  * @param string $backend_key  Backend key.
  */
 private function _changePassword($backend_key)
 {
     global $conf, $injector, $notification, $registry;
     // Check for users that cannot change their passwords.
     if (in_array($this->_userid, $conf['user']['refused'])) {
         $notification->push(sprintf(_("You can't change password for user %s"), $userid), 'horde.error');
         return;
     }
     // We must be passed the old (current) password.
     if (!isset($this->_vars->oldpassword)) {
         $notification->push(_("You must give your current password"), 'horde.warning');
         return;
     }
     if (!isset($this->_vars->newpassword0)) {
         $notification->push(_("You must give your new password"), 'horde.warning');
         return;
     }
     if (!isset($this->_vars->newpassword1)) {
         $notification->push(_("You must verify your new password"), 'horde.warning');
         return;
     }
     if ($this->_vars->newpassword0 != $this->_vars->newpassword1) {
         $notification->push(_("Your new passwords didn't match"), 'horde.warning');
         return;
     }
     if ($this->_vars->newpassword0 == $this->_vars->oldpassword) {
         $notification->push(_("Your new password must be different from your current password"), 'horde.warning');
         return;
     }
     $b_ptr = $this->_backends[$backend_key];
     try {
         Horde_Auth::checkPasswordPolicy($this->_vars->newpassword0, isset($b_ptr['policy']) ? $b_ptr['policy'] : array());
     } catch (Horde_Auth_Exception $e) {
         $notification->push($e, 'horde.warning');
         return;
     }
     // Do some simple strength tests, if enabled in the config file.
     if (!empty($conf['password']['strengthtests'])) {
         try {
             Horde_Auth::checkPasswordSimilarity($this->_vars->newpassword0, array($this->_userid, $this->_vars->oldpassword));
         } catch (Horde_Auth_Exception $e) {
             $notification->push($e, 'horde.warning');
             return;
         }
     }
     try {
         $driver = $injector->getInstance('Passwd_Factory_Driver')->create($backend_key);
     } catch (Passwd_Exception $e) {
         Horde::log($e);
         $notification->push(_("Password module is not properly configured"), 'horde.error');
         return;
     }
     try {
         $driver->changePassword($this->_userid, $this->_vars->oldpassword, $this->_vars->newpassword0);
     } catch (Exception $e) {
         $notification->push(sprintf(_("Failure in changing password for %s: %s"), $b_ptr['name'], $e->getMessage()), 'horde.error');
         return;
     }
     $notification->push(sprintf(_("Password changed on %s."), $b_ptr['name']), 'horde.success');
     try {
         Horde::callHook('password_changed', array($this->_userid, $this->_vars->oldpassword, $this->_vars->newpassword0), 'passwd');
     } catch (Horde_Exception_HookNotSet $e) {
     }
     if (!empty($b_ptr['logout'])) {
         $logout_url = $registry->getLogoutUrl(array('msg' => _("Your password has been succesfully changed. You need to re-login to the system with your new password."), 'reason' => Horde_Auth::REASON_MESSAGE));
         $registry->clearAuth();
         $logout_url->redirect();
     }
     if ($this->_vars->return_to) {
         $url = new Horde_Url($return_to);
         $url->redirect();
     }
 }