Question:
斯蒂芬和索菲亚对于一切都使用简单的密码,忘记了安全性。请你帮助尼古拉开发一个密码安全检查模块。 如果密码的长度大于或等于10个字符,且其中至少有一个数字、一个大写字母和一个小写字母,该密码将被视为足够强大。 密码只包含ASCII拉丁字母或数字。
输入:密码
输出:True or False
范例:
checkio('A1213pokl') == False
checkio('bAse730onE') == True
checkio('asasasasasasasaas') == False
checkio('QWERTYqwerty') == False
checkio('123456123456') == False
checkio('QwErTy911poqqqq') == True
Code1:
def checkio(data): flag_1,flag_2,flag_3 = 0,0,0 if len(data) > 9: for each in data: if each.islower(): flag_1 = 1 if each.isupper(): flag_2 = 1 if each.isdigit(): flag_3 = 1 if flag_1 == 1 and flag_2 == 1 and flag_3 == 1: return True else: return False else: return False
注释:
str.islower()
描述:检测字符串是否由小写字母组成。
参数:无
扫描二维码关注公众号,回复:
633381 查看本文章
返回值:字符串全由小写字母构成,则返回True,否则返回False。
str.isupper()
描述:检测字符串中所有字母是否都为大写。
参数:无
返回值:字符串全由大写字母构成,则返回True,否则返回False。
str.isdigit()
描述:检测字符串是否只由数字组成。
参数:无
返回值:如果字符串只包含数字则返回True,否则返回False。
Code2:
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
注释:
re.match(pattern,str,flags=0)
描述:尝试从字符串起始位置匹配一个模式,如果不是从起始位置匹配成功的话,match()返回none。
re.search(patten,str,flags=0)
描述:re.search 扫描整个字符串并返回第一个成功的匹配。