To build further on the code you've provided, here's a small example. You'll first have to create your dictionary of course. I called it users_and_passwords
. Keep in mind that storing users and passwords directly in a dictionary is not at all encouraged!
users_and_passwords = dict()
# get-user loop
while True:
new_user = input("Consider using alphanumeric and special characters \nCreate new user ID: ")
if len(new_user) < 4:
print("User ID must be more than 4 alphanumeric characters".upper())
continue
elif len(new_user) > 10:
print("User ID must be less than 10 alphanumeric characters".upper())
continue
else:
print("Please confirm user ID ")
break
# get-password loop
while True:
user_password = input("Create new user password: ")
# do whatever logic here
# let's assume its fine now
break
After you got your user and password variables filled properly, you can add them as a key:value pair to the dictionary like this:
users_and_passwords[new_user] = user_password
You can then iterate over your users and their passwords like so:
for k, v in users_and_passwords.items():
print (f'user: {k}\thas password: {v}')
To show that this works, with user123
as username and pass123
as a password in this example the output will be:
user:user123 has password: pass123
Watch out with storing passwords directly!
As others have pointed out already, simply scrambling your password irreversibly (e.g. by hashing it, you could take a look at this) and using the scrambled pass as a value for your user would make this a bit safer.