学python的re模板,写了个文章发现没人看,所以总结出来经验,理论没人爱,实战的人心,那么既然没人喜欢理论就直接上实战,在实战中精炼理论.不多说直接先上代码
def password_level(password): weak = re.compile(r'^((\d+)|([A-Za-z]+)|(\W+))$') level_weak = weak.match(password) level_middle = re.match(r'([0-9]+(\W+|\_+|[A-Za-z]+))+|([A-Za-z]+(\W+|\_+|\d+))+|((\W+|\_+)+(\d+|\w+))+',password) level_strong = re.match(r'(\w+|\W+)+',password) if level_weak: print 'password level is weak',level_weak.group() else: if (level_middle and len(level_middle.group())==len(password)): print 'password level is middle',level_middle.group() else: if level_strong and len(level_strong.group())==len(password): print 'password level is strong',level_strong.group()
解释一下
弱密码:全是数字,符号,字母
中等密码:数字加上符号,数字加上字母,字母加上符号
强密码:三个混合.
我没有区分大小写,希望有兴趣的可以自己写写.问题出现在\w上因为\w等价与[A-Za-z0-9_]所以前期通过\W不能匹配到包含下滑线的字符串
我们来看看中等密码,数字加上符号或者字母或者_是一个组,字母加上符号或者下划线或者符号是一个组,符号或者下划线加上字母或者数字是一个组,我总觉得这个里面的代码好像不对但是通过测试又没发现什么不对的地方,就先用这个版本0.0.1吧
测试代码
if __name__ == '__main__': passwords = ('11','aa','LL','1a','1_','a_','a1','_1','*a','1a_','1a<') for pw in passwords: password_level(pw) '''----------------------output------------------------ #password level is weak 11 #password level is weak aa #password level is weak LL #password level is middle 1a #password level is middle 1_ #password level is middle a_ #password level is middle a1 #password level is middle _1 #password level is middle *a #password level is strong 1a_ #password level is strong 1a< '''
以上所述是小编给大家介绍的使用正则表达式判断密码强弱的实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年09月20日
2024年09月20日
- 《腾格尔 容中尔甲 亚东 高原三星 男人篇 3CD》[WAV/分轨][1GB]
- 命运圣契公测实测可用兑换码大全 命运圣契最新兑换码分享
- 黑神话悟空上品疾蝠精魄获取方法一览|上品疾蝠精魄收集攻略
- 《七龙珠电光炸裂!ZERO》GT角色预告片曝光,15位新角色登场
- [ABC]安娜-胆麦发烧女声[6N纯银镀膜][2016[低速原抓WAV+CUE]
- NewViennaOctetViennaWindSoloists-TheDeccaRecordings(2024)18CD[24-48][FLAC]-7
- 雨果唱片-三角琴《俄罗斯民间音乐系列-梁祝(中国名曲)》wav
- 《塞尔达传说:智慧的再现》新实机!无之世界介绍
- 任天堂公布《塞尔达传说》系列时间线:野炊与王泪独立在外
- 任天堂更新网络投稿规范:打击影响他人游戏体验行为
- 冼佩瑾.2024-女儿Daughter(EP)【杰威尔】【FLAC分轨】
- 黑豹乐队.1993-光芒之神【摇音晨【WAV+CUE】
- 曾轶可.2011-一只猫的旅行【天娱传媒】【WAV+CUE】
- 黑神话悟空上品狼刺客精魄获取方法一览|上品狼刺客精魄收集攻略
- 视觉小说《神椿市建设中REGENERATE》将于2025年2月20日发售