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