Minor Code Changes
This commit is contained in:
1 parent
68cf821312
commit
b71b0e1689
2 files changed
+58
-77
No files matched your search
@@ -82,40 +82,32 @@ def register():
|
|||||||
|
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
print()
|
print("\n<Account setup>")
|
||||||
print("<Account setup>")
|
|
||||||
print("Type cancel at anytime to cancel.")
|
print("Type cancel at anytime to cancel.")
|
||||||
username_create = False
|
username_create = True
|
||||||
while not username_create:
|
while username_create:
|
||||||
# Sets username, password, and the wanted password to be saved.
|
# Sets username, password, and the wanted password to be saved.
|
||||||
print(" Your username must be 5 characters or longer.")
|
print(" Your username must be 5 characters or longer.")
|
||||||
userName = input(" Please set your username > ")
|
userName = input(" Please set your username > ")
|
||||||
|
|
||||||
if userName == "":
|
if userName == "": print("This cannot be blank.\n")
|
||||||
print("This cannot be blank.")
|
|
||||||
print()
|
|
||||||
|
|
||||||
elif userName in users:
|
elif userName in users: print('Username is taken, please choose a different name.\n')
|
||||||
print('Username is taken, please choose a different name.')
|
|
||||||
print()
|
|
||||||
|
|
||||||
elif len(userName) < 5:
|
elif len(userName) < 5: print("Username is too short. Please try again.\n")
|
||||||
print("Username is too short. Please try again.")
|
|
||||||
print()
|
|
||||||
|
|
||||||
elif userName == "cancel":
|
elif userName == "cancel":
|
||||||
print("< Canceling >")
|
print("< Canceling >")
|
||||||
username_create = True
|
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
home()
|
home()
|
||||||
|
break
|
||||||
|
|
||||||
else:
|
else:
|
||||||
username_create = True
|
username_create = False
|
||||||
pw_maker = False
|
pw_maker = True
|
||||||
while not pw_maker:
|
while pw_maker:
|
||||||
print(" Minimum of 8 characters")
|
print(" Minimum of 8 characters")
|
||||||
userPass: str = input(" Please set your password > ")
|
userPass: str = input(" Please set your password > \n")
|
||||||
print()
|
|
||||||
|
|
||||||
if len(userPass) >= 8:
|
if len(userPass) >= 8:
|
||||||
|
|
||||||
@@ -129,16 +121,14 @@ def register():
|
|||||||
append_file1.write('\n')
|
append_file1.write('\n')
|
||||||
append_file1.close()
|
append_file1.close()
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
print()
|
print("\nAccount has been created\n")
|
||||||
print("Account has been created")
|
savePassLoop = True
|
||||||
print()
|
|
||||||
savePassLoop = False
|
|
||||||
savePassD = {}
|
savePassD = {}
|
||||||
while not savePassLoop:
|
while savePassLoop:
|
||||||
print('When done just hit the enter key')
|
print('When done just hit the enter key')
|
||||||
savePass = input(" What password would you like to save in this account > ")
|
savePass = input(" What password would you like to save in this account > ")
|
||||||
if len(savePass) == 0:
|
if len(savePass) == 0:
|
||||||
savePassLoop = True
|
savePassLoop = False
|
||||||
elif len(savePass) > 0:
|
elif len(savePass) > 0:
|
||||||
wfor = input(' What is this password for > ')
|
wfor = input(' What is this password for > ')
|
||||||
append_file2.write(userName + ":" + str(password_encrypt(savePass.encode(), gPassword).decode()))
|
append_file2.write(userName + ":" + str(password_encrypt(savePass.encode(), gPassword).decode()))
|
||||||
@@ -148,7 +138,6 @@ def register():
|
|||||||
savePassD[wfor] = str(password_encrypt(savePass.encode(), gPassword).decode())
|
savePassD[wfor] = str(password_encrypt(savePass.encode(), gPassword).decode())
|
||||||
append_file2.close()
|
append_file2.close()
|
||||||
append_file3.close()
|
append_file3.close()
|
||||||
print()
|
|
||||||
|
|
||||||
user = User(userName, hashlib.md5(userPass.encode()).hexdigest(), savePassD)
|
user = User(userName, hashlib.md5(userPass.encode()).hexdigest(), savePassD)
|
||||||
logged_in(user)
|
logged_in(user)
|
||||||
@@ -161,9 +150,9 @@ def register():
|
|||||||
|
|
||||||
elif userPass == "cancel":
|
elif userPass == "cancel":
|
||||||
print("< Canceling >")
|
print("< Canceling >")
|
||||||
pw_maker = True
|
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
home()
|
home()
|
||||||
|
break
|
||||||
|
|
||||||
|
|
||||||
def login():
|
def login():
|
||||||
@@ -224,76 +213,73 @@ def login():
|
|||||||
data = {'username': user, 'password': users[user], 'savePass': passDict}
|
data = {'username': user, 'password': users[user], 'savePass': passDict}
|
||||||
userData[user] = data
|
userData[user] = data
|
||||||
|
|
||||||
username_check = False
|
username_check = True
|
||||||
password_check = False
|
password_check = True
|
||||||
|
|
||||||
adminName = '9581b8785e452a9d9672ddfb2277b2af'
|
adminName = '9581b8785e452a9d9672ddfb2277b2af'
|
||||||
adminPass = '9609c233f5c309419fa6393a1b959c13'
|
adminPass = '9609c233f5c309419fa6393a1b959c13'
|
||||||
|
|
||||||
print('Type cancel at anytime to cancel.')
|
print('Type cancel at anytime to cancel.\n')
|
||||||
print()
|
|
||||||
|
|
||||||
while not username_check:
|
while username_check:
|
||||||
# Takes users input for username
|
# Takes users input for username
|
||||||
inputName = input('What is your Username > ').lower().strip()
|
inputName = input('What is your Username > ')
|
||||||
|
|
||||||
# Checks if username is correct
|
# Checks if username is correct
|
||||||
if inputName in userData:
|
if inputName in userData:
|
||||||
username_check = True
|
username_check = False
|
||||||
while not password_check:
|
while password_check:
|
||||||
|
|
||||||
# Takes users input for pw
|
# Takes users input for pw
|
||||||
inputPass = input(f"Please enter password for {inputName} > ").lower().strip()
|
inputPass = input(f"Please enter password for {inputName} > ")
|
||||||
|
|
||||||
if hashlib.md5(inputPass.encode()).hexdigest() == userData[inputName]['password']:
|
if hashlib.md5(inputPass.encode()).hexdigest() == userData[inputName]['password']:
|
||||||
user = User(inputName, inputPass, userData[inputName]['savePass'])
|
user = User(inputName, inputPass, userData[inputName]['savePass'])
|
||||||
password_check = True
|
password_check = False
|
||||||
logged_in(user)
|
logged_in(user)
|
||||||
|
|
||||||
elif inputPass == "cancel":
|
elif inputPass == "cancel":
|
||||||
print("< Canceling >")
|
print("< Canceling >")
|
||||||
password_check = True
|
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
home()
|
home()
|
||||||
|
break
|
||||||
|
|
||||||
elif hashlib.md5(inputPass.encode()).hexdigest() != userData[inputName]['password']:
|
elif hashlib.md5(inputPass.encode()).hexdigest() != userData[inputName]['password']:
|
||||||
print("That is the incorrect password. Please try again.")
|
print("That is the incorrect password. Please try again.")
|
||||||
|
|
||||||
elif hashlib.md5(inputName.encode()).hexdigest() == adminName:
|
elif hashlib.md5(inputName.encode()).hexdigest() == adminName:
|
||||||
username_check = True
|
username_check = False
|
||||||
while not password_check:
|
while password_check:
|
||||||
|
|
||||||
# Takes users input for pw
|
# Takes users input for pw
|
||||||
inputAdminPass = input("Please enter password for the Admin > ")
|
inputAdminPass = input("Please enter password for the Admin > ")
|
||||||
inputAdminPass = str(inputAdminPass)
|
|
||||||
|
|
||||||
if hashlib.md5(inputAdminPass.encode()).hexdigest() == adminPass:
|
if hashlib.md5(inputAdminPass.encode()).hexdigest() == adminPass:
|
||||||
password_check = True
|
|
||||||
admin()
|
admin()
|
||||||
|
break
|
||||||
|
|
||||||
elif inputAdminPass == "cancel":
|
elif inputAdminPass == "cancel":
|
||||||
print("< Canceling >")
|
print("< Canceling >")
|
||||||
password_check = True
|
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
home()
|
home()
|
||||||
|
break
|
||||||
|
|
||||||
elif inputName == "cancel":
|
elif inputName == "cancel":
|
||||||
print("< Canceling >")
|
print("< Canceling >")
|
||||||
username_check = True
|
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
home()
|
home()
|
||||||
|
break
|
||||||
|
|
||||||
# Tells user if username is incorrect
|
# Tells user if username is incorrect
|
||||||
else:
|
else: print("That is an invalid username, please try again.")
|
||||||
print("That is an invalid username, please try again.")
|
|
||||||
|
|
||||||
|
|
||||||
def admin():
|
def admin():
|
||||||
|
|
||||||
print("\n < Welcome Braeden >\n")
|
print("\n < Welcome >\n")
|
||||||
|
|
||||||
login_op = False
|
login_op = True
|
||||||
while not login_op:
|
while login_op:
|
||||||
print(" Options:")
|
print(" Options:")
|
||||||
print(" < logout | user.list.show | user.info.show >")
|
print(" < logout | user.list.show | user.info.show >")
|
||||||
|
|
||||||
@@ -304,44 +290,40 @@ def admin():
|
|||||||
if userSelect == "logout":
|
if userSelect == "logout":
|
||||||
print(" <Logging out> from <Admin>")
|
print(" <Logging out> from <Admin>")
|
||||||
print("Logout successful")
|
print("Logout successful")
|
||||||
login_op = True
|
home()
|
||||||
|
break
|
||||||
|
|
||||||
elif userSelect == "user.list.show":
|
elif userSelect == "user.list.show": pass
|
||||||
pass
|
|
||||||
|
|
||||||
elif userSelect == "user.info.show":
|
elif userSelect == "user.info.show": pass
|
||||||
pass
|
|
||||||
|
|
||||||
elif userSelect == "":
|
elif userSelect == "": print("You cannot leave this blank.")
|
||||||
print("You cannot leave this blank.")
|
|
||||||
|
|
||||||
else:
|
else: print("That is an invalid option. Please try again.")
|
||||||
print("That is an invalid option. Please try again.")
|
|
||||||
|
|
||||||
|
|
||||||
def logged_in(user):
|
def logged_in(user):
|
||||||
append_file2 = open('UsersSP.txt', 'a')
|
append_file2 = open('UsersSP.txt', 'a')
|
||||||
append_file3 = open('WSPF.txt', 'a')
|
append_file3 = open('WSPF.txt', 'a')
|
||||||
login_op = False
|
login_op = True
|
||||||
|
|
||||||
while not login_op:
|
while login_op:
|
||||||
print("\n Options:")
|
print("\n Options:")
|
||||||
print(" < logout | my.info | reset.password | change.savedPassword >")
|
print(" < logout | my.info | reset.password | change.savedPassword >")
|
||||||
print(' < add.pass >')
|
print(' < add.pass >')
|
||||||
|
|
||||||
user_select = input(" > ")
|
user_select = input(" > ")
|
||||||
user_select = str(user_select)
|
user_select.lower()
|
||||||
|
|
||||||
if user_select == "logout":
|
if user_select == "logout":
|
||||||
print(f" <Logging out> from < {user.userName} >")
|
print(f" <Logging out> from < {user.userName} >")
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
print("Logout successful")
|
print("Logout successful")
|
||||||
login_op = True
|
|
||||||
home()
|
home()
|
||||||
|
break
|
||||||
|
|
||||||
elif user_select == "my.info":
|
elif user_select == "my.info":
|
||||||
print()
|
print('\nYour passwords:')
|
||||||
print('Your passwords:')
|
|
||||||
# Gives them the saved pw in the account
|
# Gives them the saved pw in the account
|
||||||
for r in user.savePassDict:
|
for r in user.savePassDict:
|
||||||
print(f'{r}: {password_decrypt(user.savePassDict[r].encode(), gPassword).decode()}')
|
print(f'{r}: {password_decrypt(user.savePassDict[r].encode(), gPassword).decode()}')
|
||||||
@@ -349,8 +331,8 @@ def logged_in(user):
|
|||||||
elif user_select == "reset.password":
|
elif user_select == "reset.password":
|
||||||
print("Type cancel at anytime to cancel.")
|
print("Type cancel at anytime to cancel.")
|
||||||
|
|
||||||
password_check = False
|
password_check = True
|
||||||
while not password_check:
|
while password_check:
|
||||||
password = input("Please enter your current password to activate > ")
|
password = input("Please enter your current password to activate > ")
|
||||||
if password == "":
|
if password == "":
|
||||||
print("You cant leave this blank.")
|
print("You cant leave this blank.")
|
||||||
@@ -362,9 +344,9 @@ def logged_in(user):
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
if hashlib.md5(password.encode()).hexdigest() == user.password:
|
if hashlib.md5(password.encode()).hexdigest() == user.password:
|
||||||
password_check = True
|
password_check = False
|
||||||
pw_maker = False
|
pw_maker = True
|
||||||
while not pw_maker:
|
while pw_maker:
|
||||||
print(" Minimum of 8 characters")
|
print(" Minimum of 8 characters")
|
||||||
newSavedPass = input("Please set your new password > ")
|
newSavedPass = input("Please set your new password > ")
|
||||||
|
|
||||||
@@ -389,7 +371,7 @@ def logged_in(user):
|
|||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
print("Your new password has been set")
|
print("Your new password has been set")
|
||||||
pw_maker = True
|
break
|
||||||
|
|
||||||
elif len(newSavedPass) == 0:
|
elif len(newSavedPass) == 0:
|
||||||
print("Password cant be blank.")
|
print("Password cant be blank.")
|
||||||
@@ -399,8 +381,8 @@ def logged_in(user):
|
|||||||
|
|
||||||
elif newSavedPass == "cancel":
|
elif newSavedPass == "cancel":
|
||||||
print("< Canceling >")
|
print("< Canceling >")
|
||||||
pw_maker = True
|
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
break
|
||||||
|
|
||||||
elif hashlib.md5(password.encode()).hexdigest() != user.password:
|
elif hashlib.md5(password.encode()).hexdigest() != user.password:
|
||||||
print("That is the incorrect password. Please try again.")
|
print("That is the incorrect password. Please try again.")
|
||||||
@@ -517,27 +499,26 @@ def print_user_data(user_info):
|
|||||||
|
|
||||||
|
|
||||||
def home():
|
def home():
|
||||||
system_home = False
|
system_home = True
|
||||||
while not system_home:
|
while system_home:
|
||||||
print("\n < register | login | quit | notes > ")
|
print("\n < register | login | quit | notes > ")
|
||||||
|
|
||||||
user_select = input(" > ")
|
user_select = input(" > ")
|
||||||
user_select.lower()
|
user_select.lower()
|
||||||
|
|
||||||
if user_select == "register":
|
if user_select == "register":
|
||||||
system_home = True
|
|
||||||
register()
|
register()
|
||||||
|
break
|
||||||
|
|
||||||
elif user_select == "login":
|
elif user_select == "login":
|
||||||
system_home = True
|
|
||||||
login()
|
login()
|
||||||
|
break
|
||||||
|
|
||||||
elif user_select == "quit":
|
elif user_select == "quit":
|
||||||
print("Are you sure you want to quit?")
|
print("Are you sure you want to quit?")
|
||||||
print(" < yes | no >")
|
print(" < yes | no >")
|
||||||
|
|
||||||
user_select = input(" > ")
|
user_select = input(" > ")
|
||||||
user_select = str(user_select)
|
|
||||||
|
|
||||||
if user_select == "yes":
|
if user_select == "yes":
|
||||||
exit()
|
exit()
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#Password Saver
|
# Password Saver
|
||||||
|
|
||||||
Make Sure you install all the libraries using pip
|
Make Sure you install all the libraries using pip
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user