前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >使用Python检查密码安全程度

使用Python检查密码安全程度

作者头像
Python小屋屋主
发布2018-04-16 15:32:38
1.7K0
发布2018-04-16 15:32:38
举报
文章被收录于专栏:Python小屋

本文主要演示几种内置用法的用法和代码优化技巧,所以没有使用正则表达式。

import string

def check(pwd):

#密码必须至少包含6个字符

if not isinstance(pwd, str) or len(pwd)<6:

return 'not suitable for password'

#密码强度等级与包含字符种类的对应关系

d = {1:'weak', 2:'below middle', 3:'above middle', 4:'strong'}

#分别用来标记pwd是否含有数字、小写字母、大写字母和指定的标点符号

r = [False] * 4

for ch in pwd:

#是否包含数字

if not r[0] and ch in string.digits:

r[0] = True

#是否包含小写字母

elif not r[1] and ch in string.ascii_lowercase:

r[1] = True

#是否包含大写字母

elif not r[2] and ch in string.ascii_uppercase:

r[2] = True

#是否包含指定的标点符号

elif not r[3] and ch in ',.!;?<>':

r[3] = True

#统计包含的字符种类,返回密码强度

return d.get(r.count(True), 'error')

print(check('a2Cde,'))

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2016-11-05,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 Python小屋 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档