I have a program that registers an account and I am now working on a function to log said account in. I have saved the lists "usernames" and "passwords" to separate text files.
usernames = []
passwords = []
usernames.append(username)
passwords.append(password)
usernamesFile = open("usernames.txt","a")
for usernames in usernames:
usernamesFile.write("%s\n" % usernames)
usernamesFile.close()
passwordsFile = open("passwords.txt", "a")
for passwords in passwords:
passwordsFile.write("%s\n" % passwords)
passwordsFile.close()
while True:
loginUsername = raw_input("Enter your username: ")
usernamesFile = open("usernames.txt", "r")
lines = usernamesFile.readlines()
if loginUsername in usernames:
index = usernames.index(username)
break
else:
print "Username not found"
continue
My problem is, even though I have tested the text file and it has saved all of the usernames I have registered, the search still comes back "Username not found". I am not an expert in Python so if you could please explain in a simple way that would be great!
lines, which I'm guessing is what you wanted to search through? (also: as a side note: even if you're just learning python, you should immediately purge the idea of ever storing a list of passwords in the clear).