mardi 2 juin 2020

Python If Statement question login system easy

The first thing to do is write "1" and then enter username and password. After that, the max number of account is 1 and you can then use the "2" to login. First time asking a question so I am sorry if this is like a dumb question or something. My code is as following:

https://imgur.com/a/dAaYf2u - NEW LINK

Code:

print("Type 1 for Create user. Type 2 for login")
Choice = input("Number here: ")

if Choice == ("1"):
print("Welcome to the Create a user interface")
Username = input("Username: ")
Password = input("Password: ")

if Password.count("!") > 0:
   print("Not valid - no special characters!")
else:
  file = open("account.txt", "w")
  file.write(Username)
  file.write("\n")
  file.write(Password)
  file.close()
elif Choice == ("2"):


print("Welcome, please type your Username and Password")
Loginu = input("Write username here: ")
Loginp = input("Write password here: ")
file = open("account.txt", "r")
first_line = file.readline()
if Loginu == first_line:
print("you're logged in")
else:
print("fail")

It's very basic and so on. What I don't understand is why the if Loginu == first_line can't read the first_line variable... It just jumps directly to else:

I hope it helps and I know my code is very basic lol.

Aucun commentaire:

Enregistrer un commentaire