python判断密码是否合法性_菜鸟使⽤python实现正则检测密
码合法性
# coding=gbk
import re
def ProcessMail(inputMail):
isMatch = bool(re.match(r"^[a-zA-Z](([a-zA-Z0-9]*\.[a-zA-Z0-9]*)|[a-zA-Z0-9]*)[a-zA-Z]@([a-z0-9A-Z]+\.)+[a-zA-Z]{2,}$", inputMail,re.VERBOSE));
if isMatch:
print ("邮箱注册成功。");
else:
print ("邮箱注册失败。");
return isMatch;
def ProcessPassword(inputPassword):
#处理正则表达式
isMatch = bool(re.match(r"[a-zA-Z0-9]{8}",inputPassword,flags=0));
#⽤type的三位表⽰数字type[0],⼩写字母type[1],⼤写字母type[2]是否都具备
if isMatch:
type = [False,False,False]
for i in range(0,8):
temp = inputPassword[i]
if ord(temp) >= ord('0') and ord(temp) <= ord('9'):
type[0] = True;
elif ord(temp) >= ord('a') and ord(temp) <= ord('z'):
type[1] = True;
elif ord(temp) >= ord('A') and ord(temp) <= ord('Z'):
菜鸟编辑器pythontype[2] = True;
for i in type:
if i is False:
isMatch = False;
break;
#处理是否有重复的字符出现
if isMatch:
for i in range(0,7):
temp = inputPassword[i];
for j in range(i + 1,8):
if inputPassword[j] == temp:
isMatch = False;
break;
if isMatch:
print ("密码注册成功。");
else:
print ("密码注册失败。");
return isMatch;
if __name__ == '__main__':
mailState = False;
while mailState is False:
inputMail = input("输⼊邮箱: ");
mailState = ProcessMail(inputMail);
print ("\n");
#
passwordState = False;
while passwordState is False:
inputPassword = input("输⼊密码: ");
passwordState = ProcessPassword(inputPassword); print ("\n");
输出:
输⼊邮箱: a.a9@sina
邮箱注册失败。
输⼊邮箱: 9a.aa@sina
邮箱注册失败。
输⼊邮箱: a.a.a@sina
邮箱注册失败。
输⼊邮箱: a9999@sina
邮箱注册失败。
输⼊邮箱: a123.banana@.
邮箱注册失败。
输⼊邮箱: a123.banana@a.
邮箱注册失败。
输⼊邮箱: a123.banana@sina.c
邮箱注册失败。
输⼊邮箱: a123.banana@sina
邮箱注册失败。
输⼊邮箱: a123.banana@sina
邮箱注册成功。
密码的测试也满⾜需求,不⼀⼀列举
本⽂原创发布php中⽂⽹,转载请注明出处,感谢您的尊重!相关⽂章
相关视频
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论