"); //-->
import re # 密码强度检测函数 def check_password_strength(password): score = 0 if len(password) >= 8: score += 1 if re.search(r'[a-z]', password) and re.search(r'[A-Z]', password): score += 1 if re.search(r'\d', password): score += 1 if re.search(r'[^\w]', password): score += 1 return score # 示例密码列表 passwords = [ "abcdef", "Abcdefg", "Abcdefg1", "Abcdefg1!", "StrongP@ssw0rd" ] for password in passwords: strength = check_password_strength(password) print(f"密码 '{password}' 的强度评分为 {strength} 分")
专栏文章内容及配图由作者撰写发布,仅供工程师学习之用,如有侵权或者其他违规问题,请联系本站处理。 联系我们