This is a problem from "Automate the boring stuff".
Write a function that uses regular expressions to make sure the password string it is passed is strong. A strong password is defined as one that is at least eight characters long, contains both uppercase and lowercase characters, and has at least one digit. You may need to test the string against multiple regex patterns to validate its strength.
How to improve this code?
#! /usr/bin/python3
import re
def uppercase_check(password):
if re.search('[A-Z]', password): #atleast one uppercase character
return True
return False
def lowercase_check(password):
if re.search('[a-z]', password): #atleast one lowercase character
return True
return False
def digit_check(password):
if re.search('[0-9]', password): #atleast one digit
return True
return False
def user_input_password_check():
password = input("Enter password : ")
#atleast 8 character long
if len(password) >= 8 and uppercase_check(password) and lowercase_check(password) and digit_check(password):
print("Strong Password")
else:
print("Weak Password")
user_input_password_check()