jille_Jr icon

CC: Login Script Mk.2

jille_Jr | PRO | 10/05/12 06:22:11 PM UTC | 0 ⭐ | 393 👁️ | Never ⏰ | []
Lua |

1.05 KB

|

None

|

0 👍

/

0 👎

function checkLogin(uname, pass)
  -- Yes, very easy to hack...
  if uname ~= "admin" and pass ~= "password" then
    return true
  else
    return false
  end
end
 
function login()
  local inputUname = ""
  local inputPass = ""
  local tries = 0
 
  while not checkLogin(inputUname, inputPass) do
    term.clear()
    if inputUname ~= "" or inputPass ~= "" then
      term.setCursorPos(3,2)
      print("Wrong username or password!")
    end
 
    if tries > 4 then
      term.setCursorPos(3,3)
      print("No more tries left!")
      sleep(2)
      return false
    end
 
    term.setCursorPos(3,3)
    print("Username: ") -- 10 char long
    term.setCursorPos(3,4)
    print("Password: ") -- 10 char long
    term.setCursorPos(3,5)
    print("Tries left: "..5-tries)
 
    -- Now comes the input
    term.setCursorPos(13,3)
    inputUname = read()
    term.setCursorPos(13,4)
    inputPass = read("*")
    tries = tries + 1
  end
  term.clear()
  term.setCursorPos(3,2)
  print("Correct login!")
  sleep(2)
  return true
end

Comments