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 ;}}?>