登录程序不起作用,无论输入什么

时间:2018-12-17 21:06:57

标签: python python-3.x

使用名为'UserAccounts.txt'

文件程序登录
def login():
    print("logging in, ok")
    counter = 0
    while counter <= 5:
         Username = input("Username:")
         Password = input("Password:")
         users = open("UserAccounts.txt","r")
         entry = False
     ########### v checks file v #############
         for record in users:
             if record == Username:
                 Pass = record
                 if Pass == Password:
                     print("logged in")
                     entry = True
         if entry == False:
             print("Incorret, try again")
             counter = counter + 1


     print("LOCKED: Tried over 5 times")

无论输入什么,代码始终输出:

logging in, ok
Username:El
Password:Password
Incorret, try again
Username:

你知道为什么吗? (当用户名和密码在文件中时)

感谢您的帮助,祝您有美好的一天! (可能是简单的问题,但大脑无法正常工作)

1 个答案:

答案 0 :(得分:0)

逐行读取时,该行用逗号分隔,因此在将它们声明为Passdef login(): print("logging in, ok") counter = 0 while counter <= 5: Username = input("Username:") Password = input("Password:") users = open("UserAccounts.txt","r") entry = False ########### v checks file v ############# for record in users: if record.split(',')[0] == Username: Pass = record.split(',')[1] #assuming 34 is pwd. [2] if 'Secure' is the pwd if Pass == Password: print("logged in") entry = True #maybe replace this line with "return" to stop while loop if entry == False: print("Incorret, try again") counter = counter + 1 之前,需要用逗号分隔。

function promisify(callback) {
  var promise1= new Promise(function(resolve,reject){
    callback(resolve);
   // resolve();
  })

  return promise1;
}

function myTimer(resolve) {
  setTimeout(function(){
    console.log('hello');
    resolve();
  },2000);
}

promisify(myTimer).then(function(){
  alert("jello");
})