密码复杂度检查

        斯蒂芬和索菲亚对于一切都使用简单的密码,忘记了安全性。请你帮助尼古拉开发一个密码安全检查模块。如果密码的长度大于或等于10个符号,至少有一个数字,一个大写字母和一个小写字母,该密码将被视为足够强大。密码只包含ASCII拉丁字母或数字。

输入: 密码 (str, unicode)。

输出: 密码的安全与否,作为布尔值(bool),或者任何可以转换和处理为布尔值的数据类型。你会在结果看到转换后的结果(True 或 False)。

范例:

checkio('A1213pokl') == False

checkio('bAse730onE') == True

checkio('asasasasasasasaas') == False

checkio('QWERTYqwerty') == False

checkio('123456123456') == False

checkio('QwErTy911poqqqq') == True


import re
def checkio(data):


    #replace this for solution
    regex = r'\w*[a-z]+\w*[A-Z]+\w*\d+\w*|\w*[a-z]+\w*\d+\w*[A-Z]+\w*|\w*[A-Z]+\w*[a-z]+\w*\d+\w*|\w*[A-Z]+\w*\d+\w*[a-z]+\w*|\w*\d+\w*[A-Z]+\w*[a-z]+\w*|\w*\d+\w*[a-z]+\w*[A-Z]+\w*'
    return len(data) >= 10 and re.match(regex, data) != None


#Some hints
#Just check all conditions




if __name__ == '__main__':
    #These "asserts" using only for self-checking and not necessary for auto-testing
    assert checkio('A1213pokl') == False, "1st example"
    assert checkio('bAse730onE4') == True, "2nd example"
    assert checkio('asasasasasasasaas') == False, "3rd example"
    assert checkio('QWERTYqwerty') == False, "4th example"
    assert checkio('123456123456') == False, "5th example"
    assert checkio('QwErTy911poqqqq') == True, "6th example"

    print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")


其他解决办法:

checkio = lambda s: not(

        len(s) < 10

        or s.isdigit()

        or s.isalpha()

        or s.islower()

        or s.isupper()

    ) 



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值