在python中利用for 和 if 判断密码强度

#密码强度算法

#1、长度大于八位

#2、有字母、数字、特殊符号组成(判断字母数字。isalnum() string.punctuation)

#符合其中一个条件 密码强度为低

#两个条件都符合 密码强度为高


import string

pwd = "asdad123456/./"

passwd_strong = 0

strpun = ""

if len(pwd) > 8:

    passwd_strong += 1

for i in pwd:

    if i.isalnum():

        strpun += "1"

    elif i in string.punctuation:

        strpun += "2"

if "1" in strpun and "2" in strpun:

    passwd_strong +=1

if passwd_strong == 1:

    print("密码强度为弱")

elif passwd_strong == 2:

    print("密码强度为强")

else:

    print("您输入的不符合标准")

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容