I'm very new to python and I'm trying to use a while loop that will validate a password based on several criteria but ends one all the criteria is met. Can any one give me some tips on how to make this work? I've tried using an else statement but for some reason it wont allow it.
def chk_password():
#Display info about password requirements
print('\n\nYou need a new password')
print('It must have at least six characters, but not more than 15')
print('It cannot contain any variation of \"umgc\"')
print('It cannot contain spaces')
print('It must contain the \"*\" character\n')
password = input('\nPlease enter your password:\n')
def chk_minlength():
if len(password) >= 6:
return True
else:
return False
def chk_maxlength():
if len(password) <= 15:
return True
else:
return False
def chk_spaces():
if ' ' in password:
return False
else:
return True
def chk_specchar():
if '*' in password:
return True
else:
return False
def chk_umgc():
lower_password = password.lower()
if 'umgc' in lower_password:
return False
else:
return True
chk_minlength()
chk_maxlength()
chk_spaces()
chk_specchar()
chk_umgc()
while chk_minlength == False or chk_maxlength == False or chk_spaces == False or chk_specchar == False or chk_umgc == False:
print('Your password was invalid. Please make the following corrections:')
if chk_minlength == False:
print('Your password must have at least six characters')
if chk_maxlength == False:
print('Your password cannot have more than 15 characters')
if chk_spaces == False:
print('Your password cannot any spaces')
if chk_specchar == False:
print('Your password must contain the \"*\" character.')
if chk_umgc == False:
print('Your password cannot contain any variation of \"umgc\"')
password = input('\nPlease enter your password:\n')
if chk_minlength == True and chk_maxlength == True and chk_spaces == True and chk_specchar == True and chk_umgc == True:
print('Your password met all the requirements. Thank you.')
break
chk_password()