Reputation: 37
import time
#settings file (file with username/password)
settings = "settings.txt"
#set true to skip login
login = False
while not login:
print("""
/------------------------------\\\n
/ \\\n
/ Please Enter Your Username \\\n
/ \\\n
/ \\\n
/------------------------------\\\n
""")
username = input()
print("""\n\n\n\n\n\n\n\n
/------------------------------\\\n
/ \\\n
/ Please Enter Your Password \\\n
/ \\\n
/ \\\n
/------------------------------\\\n
""")
password = input()
#open file in read and write mode
file = open(settings, "r+")
for line in file:
if "username: " in line:
line = line.replace("username: ", "")
if username == line:
print("test")
file.close()
when i run this and fill it all in it will not print test i am typeing in username but it will not work.
it gets to if username == line:
print("test")
and does not print test
The Script/application is for homework at my school
this is the settings file
username: username
password: password
Upvotes: 1
Views: 95
Reputation: 1349
input is not the correct function to use here, as it evaluates the value the user entered. Actually, it is generally unsafe to use it at all.
Upvotes: 2
Reputation: 107287
first you need to check username as string if it is in txt
file! then you have \n
at the end of your line or using line.strip()
for removing the '\n'! so change the if statement to :
if username+'\n' == line: #if user name is txt use 'username'
or
if username == line.strip():
Upvotes: 2