With this code (I added some prints to test where the code stops) I get this:
do you have your details stored here already? y/n y
Please enter a username Test
debug: username_exists is True
debug: I ran this command
do you have your details stored here already? y/n
JavaScript
x
42
42
1
import hashlib
2
import time
3
4
while True:
5
have_account = input("do you have your details stored here already? y/n ")
6
while have_account not in ("y", "n"):
7
print("please type either y or n")
8
have_account = input("y/n ")
9
if have_account == "y":
10
username_exists = False
11
while username_exists is False:
12
username_login = input("Please enter a username ")
13
with open("users.txt", "r") as f:
14
readfile = f.read()
15
if username_login in readfile:
16
username_exists = True
17
print("debug: username_exists is " + str(username_exists))
18
else:
19
username_exists = False
20
print("That user does not exist")
21
print("debug: I ran this command")
22
with open("users.txt", "r") as f:
23
readfile = f.read()
24
user_loc = readfile.index(username_login)
25
user_len = len(username_login)
26
f.seek(user_loc + user_len + 3)
27
pass_hash = f.read(64)
28
password_login_hashed = None
29
pass_matches = None
30
while pass_matches is False:
31
password_login = input("Please enter your password ")
32
password_login_hashed = hashlib.sha256(password_login.encode('utf-8')).hexdigest()
33
password_login = None
34
if password_login_hashed == pass_hash:
35
pass_matches = True
36
print("Congrats! You logged in!")
37
else:
38
pass_matches = False
39
quit_question = input("Incorrect password! Please try again or type "quit" to quit")
40
if quit_question == "quit":
41
quit()
42
Advertisement
Answer
You’re initializing pass_matches
to None
and then you’re checking pass_matches is False
which will always return False
because here pass_matches will always be None
modify the while statement with this line of code:
while pass_matches in (False, None)