@MasterJediKnight7 here is the code for the function which is method 2
@JediMasterKnigh7 and here is the first method which has more lines of code but repeats the question for user input until the conditions are met:
import re def password_1(x): while True: #input("Please enter your password: ") if re.search(r'[" ",_]', x): print("Please enter a valid password") elif re.match(r'[a-z,A-Z,0-9]',x) and re.search(r'[!@#$%^&*-+=]',x) and len(x) >= 8: print("Password accepted") break else: print("Please enter a valid password") return x password = input("Please enter your password: ") password_1(password)
@JediMasterKnigh7 and here is the first method which has more lines of code but repeats the question for user input until the conditions are met:
#///The following code works/// import re password = input("Please enter a password: ") x = True while x: if len(password) < 8 or len(password) > 16: break elif not re.search("[a-z]",password): break elif not re.search("[A-Z]",password): break elif not re.search("[0-9]",password): break elif not re.search("[@£$]",password): break elif re.search("\s",password): break else: print("Valid password") x = False break if x: print("Not a valid password")