当前位置: 首页>>代码示例>>PHP>>正文


PHP Password::setComplexity方法代码示例

本文整理汇总了PHP中Password::setComplexity方法的典型用法代码示例。如果您正苦于以下问题:PHP Password::setComplexity方法的具体用法?PHP Password::setComplexity怎么用?PHP Password::setComplexity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Password的用法示例。


在下文中一共展示了Password::setComplexity方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: validatePassword

 /**
  * Checks for valid password. Returns boolean. The following checks are done:
  *
  * + min length (constant AUTH_MIN_PASS_LENGTH defined in CAT_Users)
  * + max length (constant AUTH_MAX_PASS_LENGTH defined in CAT_Users)
  * + is a string (spaces allowed), no control characters
  * + if $allow_quotes = false: no quotes
  * + if $strict = true: consists of 6 or more letters, digits, underscores
  *                and hyphens; must contain at least one upper case letter,
  *                one lower case letter and one digit
  *
  * Use method getPasswordError() to get an error message on return value false
  *
  * @access public
  * @param  string  $password
  * @param  boolean $allow_quotes (default: true)
  * @param  boolean $strict       (default: false)
  * @return boolean
  *
  */
 public static function validatePassword($password, $allow_quotes = true, $strict = false)
 {
     $min_length = CAT_Registry::exists('AUTH_MIN_PASS_LENGTH') ? CAT_Registry::get('AUTH_MIN_PASS_LENGTH') : 5;
     $max_length = CAT_Registry::exists('AUTH_MAX_PASS_LENGTH') ? CAT_Registry::get('AUTH_MAX_PASS_LENGTH') : 20;
     // ----- check length -----
     if (strlen($password) < $min_length && (!CAT_Registry::exists('ALLOW_SHORT_PASSWORDS') || CAT_Registry::get('ALLOW_SHORT_PASSWORDS') !== true)) {
         self::$validatePasswordError = self::lang()->translate('The password is too short.');
         return false;
     } elseif (strlen($password) > $max_length) {
         self::$validatePasswordError = self::lang()->translate('The password is too long.');
         return false;
     }
     // any string that doesn't have control characters (ASCII 0 - 31) - spaces allowed
     if (!preg_match('/^[^\\x-\\x1F]+$/D', $password, $match)) {
         self::$validatePasswordError = self::lang()->translate('Invalid password!');
         return false;
     } else {
         self::$lastValidatedPassword = $match[0];
     }
     if (!$allow_quotes) {
         // don't allow quotes in the PW!
         if (preg_match('/(\\%27)|(\')|(%2D%2D)|(\\-\\-)/i', $password)) {
             self::$validatePasswordError = self::lang()->translate('Invalid password!');
             return false;
         }
     }
     // check complexity
     if ($strict) {
         $PASSWORD = new Password();
         $PASSWORD->setComplexity($PASSWORD->getComplexityStrict());
         if (!$PASSWORD->complexEnough($password, self::get_username())) {
             self::$validatePasswordError = self::lang()->translate('The required password complexity is not met') . implode('<br />', $PASSWORD->getPasswordIssues());
             return false;
         }
     }
     // all checks done
     return true;
 }
开发者ID:ircoco,项目名称:BlackCatCMS,代码行数:58,代码来源:Users.php


注:本文中的Password::setComplexity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。