Posted 23 April 2013 - 12:41 AM
So, I am making a "saving/loading" thing for my OS (MackOS)
But I get the text "Login failed" even though the login info is correct.
Why?
What am I doing wrong?
Code:
But I get the text "Login failed" even though the login info is correct.
Why?
What am I doing wrong?
Code:
function login()
term.clear()
term.setCursorPos(math.floor(w-string.len("Username:"))/2, 1)
print("Logging in")
term.setCursorPos(math.floor(w-string.len("Username:"))/2, 4)
write("Username: ")
usrName = read()
term.setCursorPos(math.floor(w-string.len("Password:"))/2, 6)
write("Password: ")
local pass = read("*")
local file2 = fs.open("users/"..usrName.."/bg", "r")
local logoPath = file2.readLine()
logo = paintutils.loadImage(logoPath)
file2.close()
file = fs.open("users/"..usrName.."/"..usrName,"r")
if not fs.exists("users/"..usrName.."/"..usrName) then
term.clear()
term.setCursorPos(math.floor(w-string.len("Login failed"))/2, 2)
print("Login failed")
sleep(1)
term.clear()
drawDesktop()
elseif fs.exists("users/"..usrName.."/"..usrName) then
local fileData = {}
local line = file.readLine()
repeat
table.insert(fileData, line)
line = file.readLine()
until line == nil -- readLine()
file.close()
local passFromFile = fileData[1]
if pass == passFromFile then
term.clear()
term.setCursorPos(math.floor(w-string.len("Login succeded!"))/2, 2)
print("Login succeded!")
sleep(1)
term.clear()
drawDesktop2()
else
term.clear()
term.setCursorPos(math.floor(w-string.len("Login failed!"))/2, 2)
print("Login failed!")
sleep(1)
term.clear()
drawDesktop()
end
end
end