Stephan and Sophia forget about security and use simple passwords for everything. Help Nikola develop a password security check module. The password will be considered strong enough if its length is greater than or equal to 10 symbols, it has at least one digit, as well as containing one uppercase letter and one lowercase letter in it. The password contains only ASCII latin letters or digits.
Input: A password as a string.
Output: Is the password safe or not as a boolean or any data type that can be converted and processed as a boolean. In the results you will see the converted results.
斯蒂芬和索菲亚对于一切都使用简单的密码,忘记了安全性。请你帮助尼古拉开发一个密码安全检查模块。如果密码的长度大于或等于10个字符,且其中至少有一个数字、一个大写字母和一个小写字母,该密码将被视为足够强大。密码只包含ASCII拉丁字母或数字。
输入: 密码。
输出: 密码的安全与否,作为布尔值(bool),或者任何可以转换和处理为布尔值的数据类型。你会在结果看到转换后的结果(True 或 False)。
def checkio(data: str) -> bool:
if data.__len__() < 10:return False
flag1 = False
flag2 = False
flag3 = False
# if re.match('[^A-Z]*[A-Z]+[^a-z]*[a-z]+[^0-9]*[0-9]+.*',str): 别人的正则方法,有问题
for i in data:
if i.isdigit():
flag1 = True
if i.islower():
flag2 = True
if i.isupper():
flag3 = True
if flag1 == False or flag2 == False or flag3 == False:
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"
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")
他人写法1:(正则的)
import re
DIGIT_RE = re.compile('\d')
UPPER_CASE_RE = re.compile('[A-Z]')
LOWER_CASE_RE = re.compile('[a-z]')
def checkio(data):
"""
Return True if password strong and False if not
A password is strong if it contains at least 10 symbols,
and one digit, one upper case and one lower case letter.
"""
if len(data) < 10:
return False
if not DIGIT_RE.search(data):
return False
if not UPPER_CASE_RE.search(data):
return False
if not LOWER_CASE_RE.search(data):
return False
return True
他人写法2:
checkio = lambda s: not(
len(s) < 10
or s.isdigit()
or s.isalpha()
or s.islower()
or s.isupper()
)
他人写法3:
def checkio(s):
fs = ''.join(filter(str.isalnum, s)) # keep only letters and digits
return (
len(fs) >= 1 # There is at least one letter or digit
and len(s) >= 10 # ... and there are at least 10 characters
and not fs.isalpha() # ... and there is at least one digit
and not fs.isdigit() # ... and there is at least one letter
and not fs.islower() # ... and not all letters are lowercase
and not fs.isupper() # ... and not all letters are uppercase
)