利用正则表达式判断密码是否符合要求,满足要求输出“密码设置成功”,否则输出“密码不符合要求,请重新设置”。密码的具体要求如下:必须由10-15位指定字符组成:数字,大写字母,小写字母,下划线,要求四种类型的字符都出现才算合法的密码。例如:Aatb32_67mnqb才是合格的强密码。
2条回答 默认 最新
关注 import re pattern = re.compile(ur'^[a-zA-Z0-9_]{10,15}$') str = u'' print(pattern.search(str))
python 代码:[纯代码]
import string num = input(">>>>>") num = set(num) chars = string.ascii_lowercase upper = string.ascii_uppercase number = {str(i) for i in range(11)} ta = {'_'} length = len(num) if 15 >= length >= 10: chars = set(chars) upper = set(upper) if num & chars and num & upper and num & number and num & ta and not num - chars - upper - number - ta: print('强密码') else: print("弱密码") else: print("bad password length")
可以参考博文:https://season.blog.csdn.net/article/details/103667744
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用