import re
def checkPassword(password):
if len(password) != 8:
return '密码长度必须为八位!'
elif re.match('^(?:(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])).{8}$', password):
return '密码正确'
else:
return '密码必须包含大小写,数字!'
password = '1qQqq13'
print(checkPassword(password))
import re
def checkPassword(password):
if re.match('^(?:(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])).{8}$', password):
return '密码正确'
else:
return '密码必须包含大小写,数字!'
password = '1qQqq13'
print(checkPassword(password))
用re模块search 判断密码规则正确与否的方法!
import re
def checkPassword(password):
passwordRegex = re.compile(r'^(?:(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])).{8}$')
moPassword = passwordRegex.search(password)
if moPassword == None:
return '密码必须包含大小写,数字。'
else:
return '密码正确'
password = '1wWqq133'
print(checkPassword(password))
*(?=.[0-9])
任意字符串后有一数字
(?=.*[a-z])
任意字符串后有一小写字母
(?=.*[A-Z])
任意字符串后有一大写字母**
本文介绍了一种使用Python的re模块来验证密码强度的方法。密码需满足特定条件:长度为8位,并同时包含大写字母、小写字母及数字。通过正则表达式的匹配来检查密码是否符合这些规则。

947

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



