如果语句不能用于密码

时间:2017-06-16 17:04:51

标签: python

我一直有问题,我有一些代码可以启动我一直在做的菜单系统,无论用户名和密码是否正确,它都不会注册它们等于?

def passw():
  f=open("userpass.txt","r")
  a=linecache.getline('userpass.txt',1)
  a=str(a)
  c=linecache.getline('userpass.txt',2)
  c=str(c)
  f.close()
  print(a+c)
  if a == "" and c == "":
    f=open("userpass.txt","a")
    user=input("Please enter a username: ")
    f.write(user)
    f.write("\n")
    password=input("Please enter a password: ")
    f.write(password)
    f.close()
    menumain()
  elif a != ""  and c != "":
    f=open("userpass.txt","r")
    user=linecache.getline('userpass.txt',1)
    user=str(user)
    user=user[0:-1]
    rpass=linecache.getline('userpass.txt',2)
    rpass=str(rpass)
    print(user,rpass)
    f.close()
    time.sleep(0.5)
    while True:
      inputUser = str(input("Enter your username: "))
      inputPass = str(input("Enter your password: "))
      if inputUser == user and inputPass == rpass:
        menumain()
      else:
        print("Incorrect username or password")

0 个答案:

没有答案