ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

用Python判断密码强度,返回bool值。大写1 小写1 数字3 其他字符3,总长12。

2021-11-20 20:32:06  阅读:153  来源: 互联网

标签:upper digit 12 Python len char bool print


char=list()

upper=【c for c in char if 'A'<=c and c<='Z' 】可以快速筛选出列表char里的大写字符

lower=【c for c in char if 'a'<=c and c<='z'】可以快速筛选出列表char里的小写字符

digit=【c for c in char if 0<=c and 0<=9】可以快速筛选出列表char里的数字

symbol=【c for c in char if not( 'A'<=c and c<='Z'  or  'a'<=c and c<='z' or 0<=c and 0<=9  )】

可以快速筛选出除字母数字外的其他字符

strong=len(upper)>=1 and len(lower)>=1 and len(digit)>=3 and len(symbol)>=3 and len(char)>=12也省了好多个if语句,使代码行数减少好多,代码简洁好多。

Python编程好简单啊,代码好漂亮啊

'''
检测密码强度
强密码条件:大写字母>=1,小写字母>=1,数字>=3,其他字符>=3,总长>=12
主要知识点:从一个列表里挑出特殊字符组成一个新列表
'''
def isStrongPassword(pwd):
	chars=list(pwd)
	upper=[c for c in chars if 'A'<=c and c<='Z']
	lower=[c for c in chars if 'a'<=c and c<='z']
	digit=[c for c in chars if '0'<=c and c<='9']
	symbol=[c for c in chars if not('A'<=c and c<='Z' or 'a'<=c and c<='z'or'0'<=c and c<='9')]
	strong=len(upper)>=1 and len(lower)>=1 and len(digit)>=3 and len(symbol)>=3 and len(pwd)>=12
	print(upper)
	print(lower)
	print(digit)
	print(symbol)

	return strong

print(isStrongPassword('StrOn9P@$^12'))
print(isStrongPassword('trOn9P@$^12'))


标签:upper,digit,12,Python,len,char,bool,print
来源: https://blog.csdn.net/m0_59272561/article/details/121439015

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有