Advertisement
programcreator

TheOS: Login

Apr 2nd, 2015
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.65 KB | None | 0 0
  1. --Variables--
  2. local notLogin = true
  3. local w,h = term.getSize()
  4. term.redirect(term.native())
  5. local user = nil
  6. local pass = nil
  7.  
  8. --Code--
  9. --Startup script--
  10. term.setBackgroundColor(colors.white)
  11. term.clear()
  12. term.setCursorPos(1,1)
  13. term.setTextColor(colors.black)
  14.  
  15. --GUI
  16. gui.resetButtons()
  17. gui.resetKeys()
  18. gui.cPrint("Login",colors.black,nil,math.floor((w-5)/2),3)
  19. gui.cPrint("Username: >",colors.gray,nil,3,6)
  20. gui.cPrint("Password: >",colors.gray,nil,3,8)
  21. gui.addField(15,6,20,1,"userField")
  22. paintutils.drawFilledBox(15,6,35,6,colors.lightGray)
  23. gui.addField(15,8,20,1,"passField")
  24. paintutils.drawFilledBox(15,8,35,8,colors.lightGray)
  25. gui.addKey(keys.enter,"Enter")
  26. gui.drawButton(15,10,8,3,colors.green,2,2,"Ready!",colors.black,"ready")
  27.  
  28. --Main Loop--
  29. while notLogin do
  30.     --Script
  31.     local result = gui.detectButtonOrKeyHit()
  32.     if result[1] == "userField" then
  33.         paintutils.drawFilledBox(15,6,35,6,colors.lightGray)
  34.         term.setCursorPos(15,6)
  35.         term.setTextColor(colors.black)
  36.         user = read()
  37.     elseif result[1] == "passField" then
  38.         paintutils.drawFilledBox(15,8,35,8,colors.lightGray)
  39.         term.setCursorPos(15,8)
  40.         term.setTextColor(colors.black)
  41.         pass = read("*")
  42.     elseif result[1] == "Enter" or result[1] == "ready" then
  43.         if user == nil or pass == nil then
  44.         else
  45.             paintutils.drawFilledBox(15,15,35,15,colors.lightGray)
  46.             local realPass
  47.             ok = pcall( function()
  48.             f = fs.open("UserData","r")
  49.             realPass = f.readAll()
  50.             f.close()
  51.             end )
  52.             if realPass == pass then
  53.                 notLogin = false
  54.             end
  55.             if ok == false or notLogin then
  56.                 gui.cPrint("Wrong username or password!",colors.red,colors.white,13,15)
  57.             end
  58.         end
  59.     end
  60. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement