练习House Password (python) 正则表达式

We have prepared a set of Editor’s Choice Solutions. You will see them first after you solve the mission. In order to see all other solutions you should change the filter.

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.
Example:

checkio('A1213pokl') == False
checkio('bAse730onE') == True
checkio('asasasasasasasaas') == False
checkio('QWERTYqwerty') == False
checkio('123456123456') == False
checkio('QwErTy911poqqqq') == True

How it is used: If you are worried about the security of your app or service, you can check your users’ passwords for complexity. You can use these skills to require that your users passwords meet more conditions (punctuations or unicode).
Precondition:
re.match(“[a-zA-Z0-9]+”, password)
0 < len(password) ≤ 64

import re
def checkio(data):
    r1=re.search(r'[a-z]+',data)
    r2=re.search(r'[A-Z]+',data)
    r3=re.search(r'[0-9]+',data)
    r4=re.search(r'\w{10,}',data)
    if r1 and r2 and r3 and 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"
    print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")

猜你喜欢

转载自blog.csdn.net/qq_43076861/article/details/82119044