900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > python判断密码是否合法性_菜鸟使用python实现正则检测密码合法性

python判断密码是否合法性_菜鸟使用python实现正则检测密码合法性

时间:2021-10-28 11:18:00

相关推荐

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'):

type[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@

邮箱注册失败。

输入邮箱: 9a.aa@

邮箱注册失败。

输入邮箱: a.a.a@

邮箱注册失败。

输入邮箱: a9999@

邮箱注册失败。

输入邮箱: a123.banana@..com

邮箱注册失败。

输入邮箱: a123.banana@a..com

邮箱注册失败。

输入邮箱: a123.banana@sina.c

邮箱注册失败。

输入邮箱: a123.banana@

邮箱注册失败。

输入邮箱: a123.banana@

邮箱注册成功。

密码的测试也满足需求,不一一列举

发布php中文网,转载请注明出处,感谢您的尊重!

相关文章

相关视频

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。