Regex to validate password strength

后端 未结 11 745
天涯浪人
天涯浪人 2020-11-22 02:13

My password strength criteria is as below :

  • 8 characters length
  • 2 letters in Upper Case
  • 1 Special Character (!@#$&*)
  • <
11条回答
  •  旧巷少年郎
    2020-11-22 02:59

    import re
    
    RegexLength=re.compile(r'^\S{8,}$')
    RegexDigit=re.compile(r'\d')
    RegexLower=re.compile(r'[a-z]')
    RegexUpper=re.compile(r'[A-Z]')
    
    
    def IsStrongPW(password):
        if RegexLength.search(password) == None or RegexDigit.search(password) == None or RegexUpper.search(password) == None or RegexLower.search(password) == None:
            return False
        else:
            return True
    
    while True:
        userpw=input("please input your passord to check: \n")
        if userpw == "exit":
            break
        else:
            print(IsStrongPW(userpw))
    

提交回复
热议问题