一种密码复杂度的简单计算方式
1, 2, 3, 4); private static $typeChange = array(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($password[$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)){ //规律性字符,不计入复杂度 $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; } /** * 获取一个字符的规律字符集 * 下列规则被认为是有规则的 * 1)重复字符 * 2)数字递增或者递减 * 3)字母递增或者递减 * @param unknown_type $prefixChar */ private static function getRegularChars($prefix, $prefixType) { $regularChars = array($prefix); switch($prefixType){ case 1: $regularChars[] = $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; } } ?>
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article
How to fix KB5055518 fails to install in Windows 10?
1 months ago
By DDD
How to fix KB5055523 fails to install in Windows 11?
1 months ago
By DDD
Roblox: Grow A Garden - Complete Mutation Guide
3 weeks ago
By DDD
Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How to fix KB5055612 fails to install in Windows 10?
3 weeks ago
By DDD

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics
Java Tutorial
1664
14


CakePHP Tutorial
1423
52


Laravel Tutorial
1317
25


PHP Tutorial
1268
29


C# Tutorial
1247
24

