Created
February 23, 2021 10:18
-
-
Save collinsrj/77e2790343d7953e61faeb62689ca6b1 to your computer and use it in GitHub Desktop.
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
# Assignment 2 | |
# Before granting a user access to a system, they need to enter a valid username and password combination. This is a very basic form of authentication. | |
# Write a program which allows a user to input a username and password. Verify that the username exists and the password entered matches the one associated with the username. | |
# Acceptance Criteria | |
# 1. If the username and password combination is incorrect, print an error message | |
# 2. If the username and password combination is correct, print a success message | |
# 3. Allow the user to enter their password up to three times before quitting the program | |
# Extra Credit (if we were grading) | |
# 1. Allow the user to create an account if it does not already exist | |
users = [ | |
{'username': 'dz88', 'password': 'super-secret'}, | |
{'username': 'DogL0ver42', 'password': 'mydogsnameisfreckles'}, | |
{'username': 'punkrock3rgir1', 'password': 'joeyramone4lyfe'}] | |
not_logged_in=True | |
attempt_count=0 | |
matched_user = False | |
while not_logged_in and attempt_count < 3: | |
username = input('Enter your username: ') | |
password = input('Enter your password: ') | |
for user in users: | |
if user["username"] == username: | |
matched_user = True | |
attempt_count = attempt_count + 1 | |
# Check if the password matches | |
if user["password"] == password: | |
not_logged_in = False | |
print(f"{username} is logged in") | |
else: | |
print("bad password") | |
if matched_user is False: | |
add_new_user = input(f"{username} is not a user. Do you want to add them? Y/n") | |
if add_new_user == "Y": | |
users.append({'username': username, 'password': password}) | |
print(f"Added {username} as a new user") | |
not_logged_in = False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment