美文网首页
php-检测密码强度

php-检测密码强度

作者: lMadman | 来源:发表于2017-01-14 15:24 被阅读0次

在用户注册的时候,很多时候需要验证一下用户设置的密码是否过于简单,那么就需要用到检测密码强度的代码,下面在网上搜集了一段检测密码强度的代码,仅供大家参考。

    $score = 0;
           if(pregqq_match("/[0-9]+/",$str))
           {
              $score ++; 
           }
           if(preg_match("/[0-9]{3,}/",$str))
           {
              $score ++; 
           }
           if(preg_match("/[a-z]+/",$str))
           {
              $score ++; 
           }
           if(preg_match("/[a-z]{3,}/",$str))
           {
              $score ++; 
           }
           if(preg_match("/[A-Z]+/",$str))
           {
              $score ++; 
           }
           if(preg_match("/[A-Z]{3,}/",$str))
           {
              $score ++; 
           }
           if(preg_match("/[_|\-|+|=|*|!|@|#|$|%|^|&|(|)]+/",$str))
           {
              $score += 2; 
           }
           if(preg_match("/[_|\-|+|=|*|!|@|#|$|%|^|&|(|)]{3,}/",$str))
           {
              $score ++ ; 
           }
           if(strlen($str) >= 10)
           {
              $score ++; 
           }
           echo "<br>";
           echo $score;

可以根据此强度,若是过于简单,不让用户提交。

相关文章

网友评论

      本文标题:php-检测密码强度

      本文链接:https://www.haomeiwen.com/subject/lxbebttx.html