写一个函数,它使用正则表达式,确保传入的口令字符串是强口令。强口令的 定义是:长度不少于 8 个字符,同时包含大写和小写字符,至少有一位数字。你可 能需要用多个正则表达式来测试该字符串,以保证它的强度。
#长度不少于 8 个字符,同时包含大写和小写字符,至少有一位数字
import re
def password_test(password):
key = True
if len(password)<8:
key =False
NumRegex_0=re.compile(r'[A-Z]').search(password)
NumRegex_1=re.compile(r'[0-9]+').search(password)
NumRegex_2=re.compile(r'[a-z]').search(password)
if (NumRegex_0==None) or (NumRegex_1==None) or (NumRegex_2==None):
key=False
if key:
print(password)
print('口令正确')
else:
print(password)
print('口令错误')