Posted 29 December 2017 - 10:55 PM
I am making a password-protected OS with encrypted password using the Crypt api, and I am having problems reading. I think the problem is it isn't reading properly, and it won't read it. If I try doing print(pass:readAll()) it returns nothing.
Heres my code:
Thanks!
Heres my code:
os.loadAPI("M-OS_Rebirthed/crypt")
local w,h = term.getSize()
local pass = fs.open("M-OS_Rebirthed/config/pass.txt", "r")
term.setBackgroundColor(colors.gray)
term.clear()
local function centerText(text)
local x,y = term.getSize()
local x2,y2 = term.getCursorPos()
term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
print(text)
end
local function writeCenterText(text)
local x,y = term.getSize()
local x2,y2 = term.getCursorPos()
term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
write(text)
end
local function drawscreen()
term.setCursorPos(w/2+25/2,3)
local logo = paintutils.loadImage("M-OS_Rebirthed/img/logo.img")
paintutils.drawImage(logo,25/2,h/2-3)
term.setCursorPos(1,h/2+3)
term.setBackgroundColor(colors.gray)
centerText("Welcome to M-OS")
end
drawscreen()
if pass.readLine() == "" then
shell.run("M-OS_Rebirthed/desktop.lua")
else
while true do
term.setCursorPos(1,h/2+4)
centerText("Please your enter password:")
term.setCursorPos(1,h/2+5)
term.setBackgroundColor(colors.lightGray)
writeCenterText(" ")
term.setCursorPos(math.ceil((w / 2) - (string.len(" ") / 2)), h/2+5)
print(pass.readAll())
input = read("#")
term.clear()
term.setTextColor(colors.black)
term.setCursorPos(1,1)
print(crypt.encrypt(input))
print(pass.readAll())
sleep(10)
if crypt.encrypt(input) == pass.readAll() then
term.setBackgroundColor(colors.gray)
term.clear()
drawscreen()
term.setCursorPos(1,h/2+3)
term.clearLine()
term.setBackgroundColor(colors.gray)
centerText("Welcome!")
sleep(2)
shell.run("M-OS_Rebirthed/desktop.lua")
else
drawscreen()
term.setCursorPos(1,h/2+3)
term.clearLine()
term.setBackgroundColor(colors.gray)
centerText("Password incorrect, please try again.")
end
end
end
Thanks!