i don't have a problem with my code but i am very new to python and programming in general so i would like some inputs as to what i could do better.
I decided to do a very simple login / register system and i am hoping you have some input so i can improve myself. I don't post here so often and don't know if this is the sort of question usually asked, but i hope you will help me. Thanks in advance.
Here is the code:
username = ['mel1', 'mel2', 'mel3']
password = ['tyr1', 'tyr2', 'tyr3']
def log_sys():
logged_in = False
log_user = raw_input('Please type in your username: ')
log_pass = raw_input('Please type in your password: ')
if log_user in username:
index = username.index(log_user)
if log_pass == password[index]:
logged_in = True
if logged_in:
print 'You are logged in'
else:
print 'Wrong username or password'
log_sys()
def reg_sys(user):
regpass1 = raw_input('Please choose a password: ')
regpass2 = raw_input('Please retype password: ')
if regpass1 == regpass2:
username.append(user)
password.append(regpass1)
log_sys()
else:
print 'Passwords did not match'
reg_sys(user)
def reglog_system():
reglog = raw_input('Do you want to register or login?: ')
if reglog == 'register':
regname = raw_input('Please choose a username: ')
reg_sys(regname)
elif reglog == 'login':
log_sys()
else:
reglog_system()
reglog_system()
This is not a complete answer; I'm not a python expert.
I would strongly suggest using an associative array or dictionary / hash instead of a list / array for storing usernames and passwords. At a minimum, the performance for large lists of users will be better.
I would move the prompt for username when the user is registering into the function for that process; It seems odd that you pass the username into reg_sys() but prompt in log_sys().
Your test for password seems flawed; You only check to see if the first matches the second, without checking to see if either or both is None, an empty list, the empty string, or some other special value.
I hope that helps.
Got some criticism after all!
1) To make clear what your main function is, you should change:
reglog_system()
to
main()
2) Call your script with:
if __name__ == "main":
main()
Makes it more portable. You can then call it directly or import it as a module
3) Use some return functions:
return raw_input("foo")
And handle the return within main(). It makes your code easier on the eyes and may help deciding when/where to deal with the result of a function.
Performance wise, I can't really criticise anything else, at least nothing springs to mind. For future planning, maybe implement hashing? SHA256 seems pretty robust these days.
i found out that if you use example = input() you can use example directly
Example:
name = input("Username: ")
if name == 'Username':
passwd = input("Password: ")
if passwd == 'Password':
print("Login Sucsessful!")
else:
print("Incorrect Username or password.")
Related
I'm new to python I got a question that might be easy but i can't get it.
i wanted to make aprogram that user gives email as username and password as password ,the program should check if email is in corect format and if its not it should print something and get email again so i used regex (Im giving this inputs to database and i thought using LIKE query but i don't think that might help)
so whats the problem with my code?!it keeps wrong email
import re
regex = r'\b[A-Za-z0-9._%+-]+#[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b'
def check(email):
if (re.fullmatch(regex, email)):
return
else:
print("corect format is like amireza#gmail.com")
return
while __name__ == '__main__':
username = input()
check(username)
password = input()
here is a working code for you:
import re
regex = r'\b[A-Za-z0-9._%+-]+#[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b'
def check(email):
if (re.fullmatch(regex, email)):
return True
else:
print("invalid input! correct format is like amireza#gmail.com")
return False
while __name__ == '__main__':
while True:
username = input("please enter email\n")
if check(username) is True:
break
password = input("please enter password\n")
break
print("username: %s, password: %s" % (username, password))
key correction:
your helper should return a boolean which lets you know if the input is legit or not. thus I returned a boolean to outside scope
one more thing: since you run it as a standalone script, the outermost while condition (while __name__ == '__main__') will always be True, which means you have to break out of it when you want to end your program execution. For simplicity I'd suggest using if __name__ == '__main__' instead
You could change your function check to return a boolean output that tells you whether the check was successful, as in
def check(email):
if (re.fullmatch(regex, email)):
return True
else:
print("corect format is like amireza#gmail.com")
return False
And then add a loop to your main code:
if __name__ == '__main__':
username = input()
while not check(username):
username = input()
Note that I did not actually run your code, but this should work.
EDIT: Heh, right, as the other answer explains, you should change your while into an if, I edited my code correspondingly.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have this very simple sign up/log in program for learning purpose, and it works. But it feels like I have code that repeats itself. The must obvious is the check functions.
My question is, should I refactor those two so they become one or is it better to keep them seperate?
def signUp():
username = input("Give me a username: ")
if checkUser(username) == True:
print("You are already registrered, please log in with your password.")
else:
password = input("Also give me a password: ")
with open("sign-up.csv", "a", newline="") as file:
writer = csv.writer(
file, delimiter=",", quotechar='"', quoting=csv.QUOTE_MINIMAL
)
writer.writerow([username, password])
print("You are now signed up. Please log in with your credentials.")
def logIn():
username = input("Give me your username: ")
password = input("Also give me your password: ")
if checkPassword(username, password) == True:
print("Welcome, you are now logged in.")
else:
print("Username or password is incorrect please try again.")
def checkUser(username):
with open("sign-up.csv", "r") as file:
reader = csv.reader(file)
myList = dict(reader)
if username in myList:
return True
else:
return False
def checkPassword(username, password):
with open("sign-up.csv", "r") as file:
reader = csv.reader(file)
myList = dict(reader)
if username in myList and password == myList[username]:
return True
else:
return False
def get_user_choice():
print("\n[1] Sign up")
print("[2] Log in")
print("[q] Quit")
return input("What would you like to do? ")
choice = ""
while choice != "q":
choice = get_user_choice()
if choice == "1":
signUp()
elif choice == "2":
logIn()
elif choice == "q":
print("Welcome back some other day")
else:
print("That choice doesn't exists")
Function checkUser is checking if a username is already present in the csv file. This would happen at signup. The function checkPassword is used when the user is signing in. These functions should stay seperate since they do dramaticly different things with different levels of security concerns. They also expect input based on where the user is in the procces of signup/login. Meaning when you write a function that does both like doBoth(username, password) you have to call this function with a null when you wanna use it at the signup fase in the application doBoth(username, null) since password is never known at signup.
The first obvious factorisation is the common part of both functions - the part tha reads the csv file into a dict:
def read_users():
with open("sign-up.csv", "r") as file:
reader = csv.reader(file)
return dict(reader)
Then you can rewrite check_user and check_password with this function:
def check_user(username):
users = read_users()
return username in users
def check_password(username, password):
users = read_users()
# make sure we work correctly even if
# someone passes `None` as password
_notfound = object()
return users.get(username, _notfound) == password
FWIW, those functions would be better named as (resp.) 'user_exists' and 'authenticate'
Also, you may want to factor out the part that's writing to the csv file - not to reduce code duplication, but to better separate the UI / domain / persistance layers.
def add_user(username, password):
with open("sign-up.csv", "a", newline="") as file:
writer = csv.writer(
file, delimiter=",", quotechar='"', quoting=csv.QUOTE_MINIMAL
writer.writerow([username, password])
def sign_up():
username = input("Give me a username: ")
# note how good naming makes code much more explicit
if user_exists(username):
print("You are already registrered, please log in with your password.")
return # no need to go further
password = input("Also give me a password: ")
add_user(username, password)
def log_in():
username = input("Give me your username: ")
password = input("Also give me your password: ")
if authenticate(username, password):
print("Welcome, you are now logged in.")
return
# oops...
print("Username or password is incorrect please try again.")
Next step would be to replace the input() calls by dedicated ask_username() and ask_password() functions that will validate the user's input. First write them as simply as possible, then find out the common part(s) and see if you can factor them out.
Note that I renamed your functions in all_lower - this is the official coding convention, and Python users tend to strongly adhere to the official coding conventions.
Also note that I removed the useless == True tests. In Python, any expression resolves to an object (in the case of a function call, to the object returned by the function), and every object has a boolean value, so if someexpression == True: is redundant at best. FWIW this is also part of pep8 (official coding conventions). And finally, when you find yourself writing something like:
if someexperession:
return True
else:
return False
You can just simplify it to
return someexpression
Try this:
def checkBoth(username, password):
with open("sign-up.csv", "r") as file:
reader = csv.reader(file)
myList = dict(reader)
if username in myList:
u = True
if password == myList[username]:
p = True
else:
p = False
else:
u = False
p = False
return (u,p)
def checkPassword(username, password):
out = [False, False]
with open("sign-up.csv", "r") as file:
reader = csv.reader(file)
myList = dict(reader)
if username in myList:
out[0] = True
if password == myList[username]:
out[1] = True
return out
and then having a check what is true on the out.
I have the following code and it is the login feature that I need help with. I have two lists - usernames and passwords. The login feature asks the user to enter a username and password. If the entered username is in the usernames list AND corresponds to the same index number in the passwords list, THEN, return "Access granted", else "Denied".
I'd be interested in two things for teaching purposes:
a) a simple fix to the problem using the two lists as specified.
b) suggestions as to the best way to solve this problem. (e.g. dictionaries, 2darrays, or anything else).
The issue is needing to iterate through both lists simulatenously and look up the same corresponding index number.
Example:
username1 and pass1 = access granted
but
username1 and pass2 =access denied
CODE:
usernames=["user1","user2","user3"]
passwords=["pass1","pass2","pass3"]
def main():
mainmenu()
def mainmenu():
print("****MAIN MENU****")
print("=======Press L to login :")
print("=======Press R to register :")
choice1=input()
if choice1=="L" or choice1=="l":
login()
elif choice1=="R" or choice1=="r":
register()
else:
print("please make a valid selection")
def login():
print("*****LOGIN SCREEN******")
username=input("Username: ")
password=input("Password: ")
if username in usernames and password in passwords:
print("yes")
else:
print("denied")
def register():
print("*****REGISTRATION****")
username=input("Enter a username:")
password=input("Enter a password:")
usernames.append(username)
passwords.append(password)
answer=input("Do you want to make another registration?")
if answer=="y":
register()
else:
registration_details()
def registration_details():
print(usernames)
print(passwords)
main()
Note: I am aware that storing the lists in a 2d array would be an obvious solution/suggestion, but this fix is necessary for pedagogical reasons - i.e students have not yet covered arrays at all. Looking at simple solutions first, but also stackoverflow users would benefit from suggestions to alternate/more efficient methods to solve this problem as well.
UPDATE:
As someone has commented below ...I thought I'd clarify. I'm aware that what is needed is to get at the index numbers of the said values in the lists. My question is - what is the best solution, or some of the solutions. Enumerate. zip. simply using a for loop? It is quite difficult to know how to start in python as there is not just one way ...any comments as to which would be the most idiomatic (pythonic) would also be useful.
BEST ANSWER:
This is possibly the best answer, presented below by Damian Lattenero
The indentation, a common error, below is off. Is it possible to also just make a quick comment on why? How to fix it?
def login():
print("*****LOGIN SCREEN******")
username=input("Username: ")
password=input("Password: ")
for ind, user in enumerate(usernames):
if username == user and passwords[ind] == password:
print("correct login")
else:
print("invalid username or password")
OUTPUT
*****LOGIN SCREEN******
Username: user3
Password: pass3
invalid username or password
invalid username or password
correct login
>>>
If you want to teach python foundations...
zip(usernames, passwords)
leads to
dict(zip(usernames, passwords))
but you could also do...
for (idx, username) in enumerate(usernames):
valid_password = passwords[idx]
I suggest to use dictionary in this case, look I'll show you how:
users_pass = {"user1" : "pass1", "user2":"pass2", "user3":"pass3"}
def login():
print("*****LOGIN SCREEN******")
username=input("Username: ")
password=input("Password: ")
if username not in users_pass:
print("The user doesnt exist")
elif users_pass[username] == password:
print("password ok")
def register():
print("*****REGISTRATION****")
username=input("Enter a username:")
password=input("Enter a password:")
users_pass[username] = password
answer=input("Do you want to make another registration?")
if answer=="y":
register()
else:
registration_details()
if you only want to use lists:
usernames=["user1","user2","user3"]
passwords=["pass1","pass2","pass3"]
def login():
print("*****LOGIN SCREEN******")
username=input("Username: ")
password=input("Password: ")
for index_of_current_user, current_user in enumerate(usernames): #enumerate allows to you to go throw the list and gives to you the current element, and the index of the current element
if username == current_user and passwords[index_of_current_user] == password: #since the two list are linked, you can use the index of the user to get the password in the passwords list
print("correct login")
else:
print("invalid username or password")
def register():
print("*****REGISTRATION****")
username=input("Enter a username:")
password=input("Enter a password:")
users_pass[username] = password
answer=input("Do you want to make another registration?")
if answer=="y":
register()
else:
registration_details()
An easy fix to your code, but not recommended, is by using zip().
You need to replace this if statement:
if username in usernames and password in passwords:
print("yes")
else:
print("denied")
by:
if (username, password) in zip(usernames, passwords):
print("yes")
else:
print("denied")
However, you can use a dict where you store your unique usernames ans password and then check if the username is in this current dict then check if the password is correct or not.
Here are a couple more methods, neither of which I'd particularly recommend, but most other decent ways have been covered in previous answers.
These methods might be better for teaching some general programming basics, but not necessarily for teaching Python...
# Both methods assume usernames are unique
usernames=["user1","user2","user3"]
passwords=["pass1","pass2","pass3"]
username = "user2"
password = "pass2"
# Method 1, with try-catch
try:
idx = usernames.index(username)
except ValueError:
idx = None
if idx is not None and password == passwords[idx]:
print "yes1"
else:
print "denied1"
# Method 2, no try-catch
idx = None
if username in usernames:
idx = usernames.index(username)
if password != passwords[idx]:
idx = None
if idx is not None:
print "yes2"
else:
print "denied2"
This is a great scenario for the zip and enumerate functions. If I read your question correctly, you want to
Iterate across both usernames and passwords simultaneously (zip)
Keep track of index (enumerate)
Given your two lists (usernames and passwords), you will want to do the following
for i, (username, password) in enumerate(zip(usernames, passwords)):
print(i, username, password)
Here's a description on what's going on.
1) The zip function is taking your usernames and passwords lists and creates a new list (an iterable zip object to be precise) where each username and password is appropriately paired.
>>> zip(usernames, passwords)
<zip object at 0x_________> # hmm, cant see the contents
>>> list(zip(usernames, passwords))
[("user1", "pass1"), ("user2", "pass2"), ("user3","pass3")]
2) The enumerate function is taking a list, and creating a new list (actually an iterable enumerate object) where each item is now paired with an index.
>>> enumerate(usernames)
<enumerate object 0x_________> # Lets make this printable
>>> list(enumerate(usernames))
[(0, "user1"), (1, "user2"), (2, "user3")]
3) When we combine these, we get the following.
>>> list(enumerate(zip(usernames, passwords))
[(0, ("user1", "pass1")), (1, ("user2", "pass2")), (2, ("user3", "pass3"))]
This gives us a list where each element is of the form (index, (username, password)). Which is super easy to use with a loop!
4) Setup your loop with the above!
for i, (username, password) in enumerate(zip(usernames, passwords)):
# Freely use i, username and password!
I am trying to make a password keeper and I have the usernames and passwords of the user accounts in a text file. However, since the script wants to know if the user input for loginUser and loginPass are in the file, that creates the opportunity for the user to log in with mismatched usernames and passwords. Can I create a list (or at least a pair of strings) and check if the input for the login variables are in a specific list?
Here's my code If you want to test it yourself:
def title():
# This is the title screen
print('____This is a password keeper____')
main()
def main():
abc = open("userpassfile.txt", "r+")
userpassfile = abc.read().strip().split()
actCheck = input('Do you already have an account?')
if(actCheck == 'Yes' or actCheck == 'yes'):
loginUser = input('What is your username?')
loginPass = input('What is yout password?')
if(loginUser and loginPass in userpassfile):
dirCheck = input('Account Settings? [y/n]')
if(dirCheck == 'y' or dirCheck == 'Y'):
print('This function is not working yet!')
else:
print('hihi')
else:
print('Incorrect password or username!')
else:
createAct = input('would you like to create one?')
if (createAct == 'Yes' or createAct == 'yes'):
createUser = input('What would you like your username to be?:')
createPass = input('What would you like your password to be?:')
abc.write(createUser + '\n')
abc.write(createPass + '\n')
open(createUser + '.txt', "w")
title()
If you have any questions about my code, please ask! Thanks!
To me, it would make more sense to store the user / pass pairs in a single line. Something like
user:pass
Or
user|pass
The problem with this approach is that you eliminate a character, the one used as the delimiter, from being used in your username or password. To get around that limitation, you can do something similar to how strings protocol works and prepend the line with a number representing the length of the username.
004userpass
014longerusernamepassword
You read the first 3 characters as an integer, and know how many more to read for the user and how many for the password.
Of course you could also store it in several other formats like json, yaml, or csv,
Given that you are storing them in pairs of lines, you should be able to break them up into their groups with code similar to this:
f = """username1
password1
username2
password2""".splitlines()
pairs = [tuple(f[i*2:i*2+2]) for i in range(len(f)/2)]
print(pairs)
This would output:
[('username1', 'password1'), ('username2', 'password2')]
Then you would simply check
if (loginUser, loginPass) in pairs:
...
You could use a more generic approach for breaking your list of usernames / passwords into pairs as well with this function
def groups(inval, size):
for i in range(0, len(inval), size):
yield inval[i:i+size]
And you could then do
pairs = tuple(groups(f, 2))
The task is to get a user to input a password then, using recursion, make sure it has no vowels in it. If it does then let the user re-enter the password. This is what i have so far:
def passwordCheck(pwd):
"""checks if pwd has any vowels in it."""#doc string
vowels = 'aeiou'#specifies the characters that aren't allowed
if pwd == '':
return 0
elif pwd == None:
return None#Shouldn't be necessary but just in case
elif pwd[0] not in vowels:#checks that the 1st(0th) character is not a vowel
return passwordCheck(pwd[1:])#gets rid of the 1st(0th) character and starts again
elif pwd[0] in vowels:#checks if the 1st(0th) character is a vowel
return 1#if it is, stops the function calls and returns a value
password = str(input('Please enter a password with no vowels in it: '))#asks user to input their new password
x = passwordCheck(password)#checks the password is valid, i.e. no vowels
while x == 1:#when the password entered contains a vowel
print('\nSorry, that is not a valid password.\nYour password cannot contain any vowels.')#tells the user why their password is invalid
password = str(input('\nPlease enter a different password: '))#gives the user a chance to re-enter their password
x = passwordCheck(password)#checks to make sure the new password is valid
print('\nCongratulations, you have entered a valid password!')#tells the user if their desired password is valid
print('\nYou are now able to log on to the system with these credentials.')#could've been included on the previous line but looks neater here
I know this is probably not the most pythonic way of doing it but it works for me in most cases. I'd love to hear a better way but ideally someone can help in the same style. I don't want to just copy someones code without understanding it.
The question i have is dealing with the case where the user enters no password at all. The first if statement:
if pwd == '':
return 0
I thought it just dealt with the case when the string had been fully recursed through, i.e. no vowels, but after a minutes inspection it's obvious this applies to no password as well.
I had also tried using:
if pwd == None:
return something
Now i'm thinking the problem could be because i said:
password = str(input('######'))
but i've fiddled with that as well and still can't can't seem to make that work either! I've tried google and searching stackoverflow but no luck so if anyone has any ideas/solution they think might be helpful I'd be very grateful to hear them. Thank you very much.
My main question is:
How can i differentiate between a string that's empty because it's been recursed through and the user inputting nothing?
Solved.
ended up using
def passwordValid(pwd):
if len(pwd)>0 and passwordCheck(pwd)==0:
return pwd
else: return 'Fail'
password = str(input('Please enter a password with no vowels in it: '))#asks user to input their new password
y = passwordValid(password)#checks the password is valid, i.e. no vowels
while y == 'Fail':#when the password entered contains a vowel
print('\nSorry, that is not a valid password.\nYour password cannot contain any vowels or be empty.')#tells the user why their password is invalid
password = str(input('\nPlease enter a different password: '))#gives the user a chance to re-enter their password
y = passwordValid(password)#checks to make sure the new password is valid
print('\nCongratulations, you have entered a valid password!')#tells the user if their desired password is valid
print('\nYou are now able to log on to the system with these credentials.')#could've been included on the previous line but looks neater here
Thank you Wayne Werner for fixing the title and the main question.
This problem can be broken down into (at least) three distinct subproblems:
check whether a string contains vowels
check whether a string is a valid password (length > X and has vowels)
get a password from the user
Your code should reflect this structure. You could therefore use the following function layout:
def has_vowels(string):
if not string: # check for empty string
return False # empty strings never have vowels
# TODO we have a non-empty string at this point and can use recursion
def is_valid_password(string):
return len(string) > 0 and not has_vowels(string)
def request_password():
while True: # use an endless loop here, we don't won't to repeat
# the "input" statement. We could also change this to
# something like `for i in range(3)` to allow only a limited
# number of tries.
passwd = input('Please enter a password with no vowels in it: ')
# TODO check if input is valid, if yes, return, if no, print an error
Don't attempt to solve both problems with a single method. You have two ditinct critera: no vowels; minimum length.
def isPasswordValid(pwd):
return len(pwd) > 4 and not passwordCheck(password)
x = isPasswordValid(password)
...
You could solve this with recursion by adding another parameter which indicates how many characters have been looped through, but that is clumsy and offers no real benefit.
You can't differentiate between an empty string and an empty string. You can however set the variable to None, or to a string like "__no_string_entered_yet". That said, I don't see why you would need to, see the other answers.
I believe this does what your question asks for:
Not allow an empty password (different than a "blank" password?)
Not allow vowels in the password
I opted not use if/elif/else in favor of structuring it so that valid characters "fall through"
def pwd_check(s):
vowels = 'aeiou'
if len(s) == 0: return False # This is only valid in the first iteration
if s[0] in vowels: return False
if len(s) == 1: return True # Success: a 1 character pwd with no vowels
return pwd_check(s[1:])
I thought about putting checks in to make sure that a string like ' ' was not passed in, but I didn't see that explicitly asked for. pwd_check(password.strip()) solves this problem.
Here's how I like to do.
For the fun, I added conditions of minimum and maximum lengths for the password:
def passwordCheck(pwd,vowels = 'aeiou',minimum=5,maximum=12):
if pwd == '':
return 0,None,None
elif pwd[0] in vowels:
return -1,None,None
else:
y = passwordCheck(pwd[1:])[0]
if y==-1:
return -1,None,None
else:
return y + 1,minimum,maximum
mess = 'Please enter a password with no vowels in it: '
while True:
x,miin,maax = passwordCheckstr(input(mess))
if x==-1:
mess = ('\nSorry, that is not a valid password.\n'
'Your password cannot contain any vowels.\n'
'Please enter a different password: ')
elif x==0:
mess = ('\nSorry, you must enter a password.\n'
'Please do enter a password: ')
elif x<miin:
mess = ('\nSorry, the password must have at least %d characters.\n'
'The string you entered has %d characters.\n'
'Please, enter a new longer password: ' % (miin,x))
elif x>maax:
mess = ('\nSorry, the password must have at most %d characters.\n'
'The string you entered has %d characters.\n'
'Please, enter a new shorter password: ' % (maax,x))
else:
print ('\nCongratulations, you have entered a valid password!\n'
'\nYou are now able to log on to the system with these '
'credentials.')
break
edit
Another kind of algorithm.
I wasn't satisfied to return such tuple as -1,None,None
def check_password(forbidden,minimum,maximum):
def passwordCheck(pwd,cnt=0,forbid = forbidden,
miin=minimum,maax = maximum):
# cnt is the number of preceding turns of recursion
# that have been already executed.
if pwd == '':
if cnt==0:
# cnt==0 means that it's the first turn of recursion
# since pwd is '', it means no entry has been done
return 0
elif cnt<miin:
return -3
elif cnt>maax:
return -2
elif pwd[0] in forbid:
return -1
else:
if cnt in (-3,-2,-1):
return cnt
else:
return passwordCheck( pwd[1:] , cnt+1 )
mess = 'Please enter a password with no vowels in it: '
while True:
x = str(raw_input(mess)).strip()
y = passwordCheck(x)
if y==0: # inexistent string
mess = ('\nSorry, you must enter a password.\n'
'Please do enter a password: ')
elif y==-1: # string contains a vowel
mess = ('\nSorry, that is not a valid password.\n'
'Your password cannot contain any vowels.\n'
'Please enter a different password: ')
elif y==-2: # string too long
mess = ('\nSorry, the password must have at most %d characters.\n'
'The string you entered has %d characters.\n'
'Please, enter a new shorter password: ' % (maximum,len(x)))
elif y==-3: # string too short
mess = ('\nSorry, the password must have at least %d characters.\n'
'The string you entered has %d characters.\n'
'Please, enter a new longer password: ' % (minimum,len(x)))
else: # success
print ('\nCongratulations, you have entered a valid password!\n'
'You are now able to log on to the system with these credentials.')
break
# EXECUTION
check_password('aeiou',5,12)