checkio-house password

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

输入: 密码 (str, unicode)。

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

Example:
checkio(‘A1213pokl’) == False
checkio(‘bAse730onE’) == True
checkio(‘asasasasasasasaas’) == False
checkio(‘QWERTYqwerty’) == False
checkio(‘123456123456’) == False
checkio(‘QwErTy911poqqqq’) == True

如何使用: 如果你担心你的应用或服务的安全性,您可以检查用户密码的复杂性。你可以使用这些技巧要求你的用户的密码符合多个条件(标点符号或unicode)。

import re
def checkio(data):
    r1=re.search(r'[0-9]+',data)
    r2=re.search(r'[a-z]+',data)
    r3=re.search(r'[A-Z]+',data)
    r4=re.match(r'\w{10,}',data)
    if bool(r1) and bool(r2) and bool(r3) and bool(r4):
        return True
    else:
        return False
    #replace this for solution
    #return True or False

#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"

注意re.match和re.search
re.match(‘\d’,aa33) -none(从字符串首部匹配)
re.search(‘\d’,aa33)–not none

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值