I realize this is an old topic but, wanted to reply.
This is in no way a complete working script but, could do something like this.
I would suggest using a database such as sqlite3 or mysql for storing user data or maybe a json file as it would make it easier.
from string import ascii_letters, digits
from random import sample
characters = ascii_letters + digits + '@!?&#'
def generate():
return ''.join(sample(characters, 10))
def check_newuser(new_user):
if new_user:
return True
return False
def check(username, password):
# Do user validation stuff
if username:
return True
return False
main_menu = ['A: Login','B: Create Account','C: Quit']
print('What would you like to do?')
while True:
print(f"Options: {', '.join(main_menu)}")
option = input('Choose an option\n>> ')
if option.lower() not in ['a','b','c']:
print('That is not a valid option.')
if option.lower() == 'c':
print('Goodbye!')
break
if option.lower() == 'a':
username = input('Please enter your username\n>> ')
password = input('Please enter your password\n>> ')
validate = check(username, password)
if validate:
print(f'User {username} logged in')
else:
print('Sorry that username or password is not correct.')
if option.lower() == 'b':
new_user = input('Please enter a username\n>> ')
check_user = check_newuser(new_user)
if check_user:
print('Options: 1 create own password, 2 generate random password')
new_password_option = input('Choose an option\n>> ')
if new_password_option == '1':
newpass = input('Enter a new password\n>> ')
elif new_password_option == '2':
newpass = generate()
else:
print('That is not a valid option')
print(f'Your password is {newpass}')
else:
print('That username has already been taken')
# Go back and ask for new username