Home > Back-end >  Searching for specific information in a file
Searching for specific information in a file

Time:10-29

So, I have a program that acts like a local login/signup system. It asks the user if they want to signup, or login. If they signup, they shall type a username and password in a certain format and it puts it in a file.

If they choose to login, the program will assume that what they're about to type in is located in the file. The intended use is that if it is in the file, it will say that the account is valid. If the thing that the user typed in isn't located in the file, it should say that it is not a valid account.

As of now, the output always says that the account isn't valid, even though it is in the file. Here is the login portion of the code:

elif sol == "l":
os.system("clear")
print("You have chosen to login.")
time.sleep(2)
os.system("clear")

datasearch = input("What is your username and password?(username/password): ")

with open ("user_database.txt", "r") as searchdata:
    if datasearch in os.linesep:
        os.system("clear")
        print("This is a valid account!")
        time.sleep(3)
        os.system("clear")
        quit()
    else:
        os.system("clear")
        print("This is not a valid account!")
        time.sleep(3)
        os.system("clear")

CodePudding user response:

You are not searching the file. You are checking if the users input is in os.linesep.
You should put something like if datasearch in searchdata.read(): inplace of if datasearch in os.linesep: in your code.

  • Related