7.18.1 强口令检测
写一个函数,它使用正则表达式, 确保传入的口令字符串是强口令。 强口令的
定义是: 长度不少于 8 个字符, 同时包含大写和小写字符, 至少有一位数字。你可
能需要用多个正则表达式来测试该字符串, 以保证它的强度。
import pyperclip, re
lenRegex = re.compile(r'\w{8,}')
lowerRegex = re.compile(r'[a-z]')
capitalRegex = re.compile(r'[A-Z]')
numberRegex = re.compile(r'[0-9]')
def checkpw(psw):
if lenRegex.search(psw) and lowerRegex.search(psw) and capitalRegex.search(psw) and numberRegex.search(psw):
return True
return False
本文介绍了一个使用正则表达式检查口令强度的函数。该函数确保口令长度不少于8个字符,且同时包含大小写字母及数字,有效提升账户安全性。
285

被折叠的 条评论
为什么被折叠?



