I am new to the world of Python and have been given the task to complete the following:
Design, code, test and evaluate a system to accept and test a password for certain characteristics:
- It should be at least 6, and no more than 12 characters long.
- The system must indicate that the password has failed and why, asking the user to re-enter their choice until a successful password is entered.
- A message to indicate that the password is acceptable must be displayed.
- Password strength can be assessed against simple criteria to assess its suitability; for example a password system using only upper and lower case alphabetical characters and numeric characters could assess the password strength as:
- WEAK if only one type used, e.g. all lower case or all numeric
- MEDIUM if two types are used
- STRONG if all three types are used.
So far I have done the following but not got it to work correctly:
def password():
print ('Welcome user ! Please enter password below\n')
print ('The password entered must be between 6-12 characters long\n')
while True:
password = input ('Please enter your password . . . :')
weak = 'weak'
med = 'medium'
strong = 'strong'
if len(password) >12:
print ('password is too long It must be between 6 and 12 characters')
elif len(password) <6:
print ('password is too short It must be between 6 and 12 characters')
elif len(password) >=6 and len(password) <= 12:
print ('password ok\n')
if password.lower()== password or password.upper()==password or password.isalnum()==password:
print ('password is', weak)
elif password.lower()== password and password.upper()==password or password.isalnum()==password and password.upper()==password:
print ('password is', medium)
else:
password.lower()== password and password.upper()==password and password.isalnum()==password
print ('password is', strong)
break
password()
I have tried to introduce a while
loop:
while invalid:
if len(password) >=6 and (password) <=12:
password=False
# number in range
# sets invalid to False to stop loop
else:
print('Sorry the password you entered was not between 6 and 12 characters long')
print('Please try again')
print('You have entered a valid password')
But still cant get it to work Please help !!!