Permalink
Cannot retrieve contributors at this time
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?
chatbot-personal-contribution/Login_Systems/login_systems.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
40 lines (34 sloc)
1.85 KB
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
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? ") |