我当前正在创建一个非常简单的登录系统,其中文件存储在客户端计算机上,而登录信息存储在名为loginInfo.txt的文件中。文件已创建,运行时我输入了正确的信息,但登录失败。这是代码
class UserInfo():
def login():
try:
loginInfo = open('loginInfo.txt', 'r')
loginInfo_LineByLine = loginInfo.readlines() # create a list of each line in the login info file
correctUsername = loginInfo_LineByLine[0] # store what the correct username is
correctPassword = loginInfo_LineByLine[1] # store what the correct password is
loginInfo.close() # we don't need anymore data from the login file so we can close it
inputtedUsername = input('Username: ') # get a usename and password from the user
inputtedPassword = input('Password: ')
if(inputtedUsername == correctUsername):
# checks if the correct info was entered
if(inputtedPassword == correctPassword):
# if the correct info was entered then give the user sudo priviledges and get their email info for email sending
sudo = True
email = input('Email(allow less secure apps must be enabled): ')
password = input('Email Password: ')
global username
username = inputtedUsername
print("hi")
else:
# if incorrect info was entered return an error
print(inputtedPassword)
print(correctPassword)
print(inputtedUsername)
print(correctUsername)
print(inputtedPassword == correctPassword and inputtedUsername == correctUsername)
print('Login failed restart Geeko Helpr if you wish to try again otherwise you will not have access to sudo features')
global username
username = inputtedUsername
except IOError:
# alert the user that no login info was found
print('Your login info doesn\'t seem to exist please create a login')
loginInfo = open('loginInfo.txt', 'a+') # create the login info file
loginUsername = input('What would you like to be your username: ') # ask fo a username and password and store them as variables for later
loginPassword = input('What would you like to use as your password: ')
loginInfo.write(loginUsername + "\n")
loginInfo.write(loginPassword)
loginInfo.close()
quit()
此代码在启动时被调用。我没有收到任何错误,但登录失败。无论是否打印,都会在False
中传递正确的信息。