题目 强口令检测
写一个函数,它使用正则表达式,确保传入的口令字符串是强口令。强口令的定义是:长度不少于 8 个字符,同时包含大写和小写字符,至少有一位数字。你可能需要用多个正则表达式来测试该字符串,以保证它的强度。
代码
下面展示代码
#! python3
# StrongPasswordDetection.py # 强口令检测 输入一段口令
# 强口令:长度不少于8个字符 同时包含大写和小写 至少有一位数字
import re
def StrongPasswordDetection(password):
if len(password) >= 8:
passRegex_1 = re.compile(r'[a-z]').search(password)
passRegex_2 = re.compile(r'[A-Z]').search(password)
passRegex_3 = re.compile(r'\d').search(password)
if passRegex_1 and passRegex_2 and passRegex_3:
print('this password is StrongPassword')
else:
print('this password is not StrongPassword')
else:
print('this password is not StrongPassword')
PassWord = input()
StrongPasswordDetection(PassWord)
结果
12344Saffsg676
this password is StrongPassword
122334456
this password is not StrongPassword
1212233
this password is not StrongPassword
123asD
this password is not StrongPassword
aaaaaaaaFFFF
this password is not StrongPassword
IIIIffg4565
this password is StrongPassword
代码均是本人所写,初识Python,如程序有不规范之处,请多多留言