Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
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? ") |