Skip to content
Permalink
02a482779e
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
40 lines (34 sloc) 1.85 KB
import Databases.database_interaction as databaseInteraction
from getpass import getpass
#declare global CONSTANTS
MAX_REGISTER_ATTEMPTS = 4
MAX_LOGIN_ATTEMPTS = 4
#omitted code that isn’t mine
#for register
for attempts in range(MAX_REGISTER_ATTEMPTS, 0, -1):
username = input('To register: Enter username >').strip()
password = input('Enter password >')
try:
databaseInteraction.CreateUser(username, password)
return system_type,username,input("Registration and login successful. What would you like to ask me? ")
except: #raised if username not unique
print('Error: Username already exists.')
print('Attempts remaining: ' + str(attempts - 1))
print('Out of attempts. Logging in as Guest.')
return system_type,"Guest",input("What would you like to ask me? ")
#omitted code that isn’t mine
#for login
for attempts in range(MAX_LOGIN_ATTEMPTS, 0, -1):
username = input('To login: Enter username >')
#usage for getpass found from https://stackoverflow.com/a/9202236
password = getpass('Enter password (input hidden) >')
userExists, successful = databaseInteraction.CheckUsernamePasswordMatch(username, password)
if successful:
return system_type,username,input("Login successful. What would you like to ask me? ")
elif userExists:
print('Password incorrect.')
else:
print('Username incorrect.')
print('Attempts remaining: ' + str(attempts - 1))
print('Out of attempts. Logging in as Guest.')
return system_type,"Guest",input("What would you like to ask me? ")