共使用了两种方式
方式(一):
#强口令检测
import re
def main():
print('请输入用户名:')
shuru = input()
judgelenth(shuru)
def judgelenth(zifulenth):
if len(zifulenth) >= 8:
judgebigsmall(zifulenth)
else:
print('字符串长度要大于等于8')
def judgebigsmall(zifubs):
bss=re.compile(r'[a-z]+')
bsb=re.compile(r'[A-Z]+')
if bss.search(zifubs) and bsb.search(zifubs):
return True
judgenumber(zifubs)
else:
print("必须有大小写字母")
return main()
def judgenumber(zifuchuan):
nm=re.compile(r'\d')
if nm.search(zifuchuan):
print('账号合规')
else:
print('账号需要包含数字')
return main()
if __name__=='__main__':
main()
方式(二):
import re
judgelenth=re.compile(r'\w{8,}')
judgebs=re.compile(r'[A-Z].*[a-z]|[a-z].*[A-Z]')
judgenm=re.compile(r'\d{1,}')
def main():
print("请输入密码:")
getshuru=input()
if judgenm.search(getshuru) and judgebs.search(getshuru) and judgelenth.search(getshuru):
print("hegui")
else:
print("需大于8位且有大小写")
if __name__=='__main__':
main()
对于一句正则把这个强口令检测都搞定的没有想到,希望大佬补充下