A simple computing method for password complexity-PHP source code

Source: Internet
Author: User
A simple computing method for password complexity
1, 2, 3, 4); private static $ typeChange = array (1, 2), array (1, 3), array (1, 4 ), array (2, 3), array (2, 4), array (3, 4); private static $ typeChangeComplexs = array (1, 1, 2, 1, 2, 2); public static function computeComplex ($ password) {$ complex = 0; $ password = (string) $ password; $ length = strlen ($ password); $ prefixType = 0; $ regularChars = array (); for ($ I = 0; $ I <$ length; $ I ++) {if (ctype_digit ($ passwor D [$ I]) {$ type = 1;} elseif (ctype_lower ($ password [$ I]) {$ type = 2 ;} elseif (ctype_upper ($ password [$ I]) {$ type = 3 ;}else {$ type = 4 ;}if (! In_array ($ password [$ I], $ regularChars) {// regular character, not included in complexity $ complex + = self ::$ typeComplexs [$ type]; if ($ prefixType) {$ changeType = array ($ type, $ prefixType); sort ($ changeType); $ change = array_search ($ changeType, self: $ typeChange ); if ($ change! = False) {$ complex + = self: $ typeChangeComplexs [$ change] ;}}$ prefixType = $ type; $ regularChars = self :: getRegularChars ($ password [$ I], $ prefixType);} return $ complex ;} /*** obtain the regular character set of a character * The following rules are regarded as rule * 1) repeated characters * 2) numbers increase or decrease * 3) increase or decrease letters * @ param unknown_type $ prefixChar */private static function getRegularChars ($ prefix, $ prefixType) {$ regularChars = array ($ prefix); switch ($ prefixType) {case 1: $ regularChar S [] = $ prefix + 1; $ regularChars [] = $ prefix-1; break; case 2: case 3: $ regularChars [] = chr (ord ($ prefix) + 1); $ regularChars [] = chr (ord ($ prefix)-1); $ regularChars = array_filter ($ regularChars, 'ctype _ alnum'); break ;} return $ regularChars ;}}?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.