每日练习——检查密码强度

定义一个名为“isStrongPassword”的函数,该函数将字符串作为参数。功能然后将检查所提供的字符串是否满足以下条件,
以检查是否为强 密码:
1.必须至少包含1个大写和小写字母的组合
2.必须至少包含3位数字
3.必须至少包含3个特殊字符(包括空格)
4.密码长度必须至少12个字符
该函数将返回一个布尔值,即如果满足所有条件则返回True或返回False
确保使用可能返回False值的每个可能的输入来测试函数也一样
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

def isStrongPassword(pwd):
    chars = list(pwd)
    # 大写字母A~Z
    upper = [c for c in chars if 'A' <= c and c <= 'Z']
    # 小写字母a~z
    lower = [c for c in chars if 'a' <= c and c <= 'z']
    # 数字0~9
    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')]
    #判断为TRUE的条件:
    #1.必须至少包含1个大写和小写字母的组合 
    #2.必须至少包含3位数字
    #3.必须至少包含3个特殊字符(包括空格)
    #4.密码长度必须至少12个字符 
    strong = len(upper) >= 1 and len(lower) >= 1 and len(digit) >= 3 and len(symbol) >= 3 and len(pwd) >= 12
    return strong
print(isStrongPassword("Str0n9P@$$w0rd"))
print(isStrongPassword("StrongPassword"))
print(isStrongPassword("Stron9P@$$0rd"))
print(isStrongPassword("Str0n9Pass0rd"))
print(isStrongPassword("str0n9p@$$0rd"))
print(isStrongPassword("Str0n9P@$$"))
print(isStrongPassword("12345678"))
print(isStrongPassword("~!@#$$%^&*()_+"))
print(isStrongPassword("STRONGPASSWORD"))
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

清风缘明月心

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值