Last active
March 5, 2016 00:47
-
-
Save Kwisses/1c871d640f6b64cb5288 to your computer and use it in GitHub Desktop.
[Daily Challenge #5 - Easy] - Password Protected - r/DailyProgrammer
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
# ***** DAILY CHALLENGE #5 - EASY ***** | |
# Your challenge for today is to create a program which is password protected, and wont open unless the correct user | |
# and password is given. | |
# | |
# For extra credit, have the user and password in a separate .txt file. | |
# | |
# For even more extra credit, break into your own program :) | |
# --------------------------------------------------------------------------------------------------------------------- | |
def password_protected(): | |
"""Password protects file access; asks for username and password. """ | |
username = input("Enter Username: ") | |
password = input("Enter Password: ") | |
user_pw = open("Challenge_5_easy_pw.txt", "r") | |
user_pw_read = user_pw.read() | |
if username in user_pw_read and password in user_pw_read: | |
return "Access Granted!" | |
# file to open goes here. | |
else: | |
print("Username and/or password denied.") | |
password_protected() | |
def hack(): | |
"""Opens .txt where user info is stored and returns the username and password for password_protected(). | |
I could make it so password_protected() takes two arguments (username, password) then use the return values from | |
this program as parameters, but that makes password_protected() less secure. | |
""" | |
user_info = open("Challenge_5_easy_pw.txt", "r") | |
info = user_info.read().split() | |
return info | |
file_access = password_protected() | |
print(file_access) | |
hack = hack() | |
print(hack) |
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
Kwisses hello |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
[Daily Challenge #5 - Easy] from the DailyProgrammer subreddit. Password Protected file. Includes bonus .txt file where username and password is contained.
Reference: https://www.reddit.com/r/dailyprogrammer/comments/pnhyn/2122012_challenge_5_easy/