Advertisement
AquaJD

SSE Login

Feb 2nd, 2017
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.43 KB | None | 0 0
  1. tColors = {
  2.   ["m_bg"] = colors.white,
  3.   ["m_text"] = colors.black,
  4.   ["t_bg"] = colors.blue,
  5.   ["t_text"] = colors.white,
  6.   ["b1_bg"] = colors.cyan,
  7.   ["b2_bg"] = colors.cyan,
  8.   ["b3_bg"] = colors.green,
  9.   ["b_text"] = colors.white  
  10. }
  11.  
  12. tButton = {
  13.   ["b1_x"] = 4,
  14.   ["b1_y"] = 4,
  15.   ["b1_w"] = 20,
  16.   ["b1_h"] = 4,
  17.   ["b1_text"] = "Username",
  18.   ["b2_x"] = 4,
  19.   ["b2_y"] = 10,
  20.   ["b2_w"] = 20,
  21.   ["b2_h"] = 4,
  22.   ["b2_text"] = "Password",
  23.   ["b3_x"] = 4,
  24.   ["b3_y"] = 16,
  25.   ["b3_w"] = 9,
  26.   ["b3_h"] = 3,
  27.   ["b3_text"] = "Login",
  28. }
  29.  
  30. userInput = ""
  31. passInput = ""
  32. passInputN = ""
  33. bRunning = true
  34.  
  35. function drawBox(x,y,w,h,cb,ct,text,ce,extra)
  36.   term.setBackgroundColor(cb)
  37.   term.setTextColor(ct)
  38.   term.setCursorPos(x,y)
  39.   for i=1,h do
  40.     for i=1,w do
  41.       write(" ")
  42.     end
  43.     term.setCursorPos(x,y+i)
  44.   end
  45.   if h == 2 or h == 4 or h == 6 or h == 8 or h == 10 then
  46.     term.setCursorPos(x+(w/2)-(#text/2),y+(h/2)-1)
  47.   else
  48.     term.setCursorPos(x+(w/2)-(#text/2),y+(h/2))
  49.   end
  50.   print(text)
  51.   term.setCursorPos(x+(w/2)-(#extra/2),y+(h/2)+1)
  52.   term.setTextColor(ce)
  53.   print(extra)
  54. end
  55.  
  56. function dispSuccess()
  57.   drawBox(tButton["b3_x"],tButton["b3_y"],17,tButton["b3_h"],colors.lime,tColors["b_text"],"Access Granted",tColors["b_text"],"")
  58.   sleep(1)
  59.   bRunning = false
  60. end
  61.  
  62. function dispFailure()
  63.   drawBox(tButton["b3_x"],tButton["b3_y"],17,tButton["b3_h"],colors.red,tColors["b_text"],"Access Denied",tColors["b_text"],"")
  64.   sleep(1)
  65.   drawBox(tButton["b3_x"],tButton["b3_y"],tButton["b3_w"],tButton["b3_h"],tColors["b3_bg"],tColors["b_text"],tButton["b3_text"],tColors["b_text"],"")
  66. end
  67.  
  68. function redraw()
  69.   term.setBackgroundColor(tColors["m_bg"])
  70.   term.clear()
  71.   term.setCursorPos(2,2)
  72.   term.setBackgroundColor(tColors["t_bg"])
  73.   term.clearLine()
  74.   term.setCursorPos(2,2)
  75.   term.setTextColor(tColors["t_text"])
  76.   term.setBackgroundColor(tColors["t_bg"])
  77.   print("Security System Example")
  78.   drawBox(tButton["b1_x"],tButton["b1_y"],tButton["b1_w"],tButton["b1_h"],tColors["b1_bg"],tColors["b_text"],tButton["b1_text"],colors.lightGray,userInput)
  79.   drawBox(tButton["b2_x"],tButton["b2_y"],tButton["b2_w"],tButton["b2_h"],tColors["b2_bg"],tColors["b_text"],tButton["b2_text"],colors.lightGray,passInputN)
  80.   drawBox(tButton["b3_x"],tButton["b3_y"],tButton["b3_w"],tButton["b3_h"],tColors["b3_bg"],tColors["b_text"],tButton["b3_text"],colors.lightGray,"")
  81. end
  82.  
  83. function checkCreds()
  84.     local success = false
  85.     if fs.exists("/sse/.users/."..userInput) then
  86.       local userFile = fs.open("/sse/.users/."..userInput,"r")
  87.       local userFile_pass = userFile.readLine()
  88.       if userFile_pass == passInput then
  89.         success = true
  90.       end
  91.       userFile.close()
  92.     end
  93.     if success == false then
  94.         return false
  95.     else
  96.         return true
  97.     end
  98. end
  99.  
  100.  
  101. redraw()
  102. while bRunning do
  103.   local event, button, X, Y = os.pullEvent()
  104.   if event == "mouse_click" then
  105.     if button == 1 then
  106.       if X >= tButton["b1_x"] and X <= (tButton["b1_x"] + tButton["b1_w"] - 1) and Y >= tButton["b1_y"] and Y <= (tButton["b1_y"] + tButton["b1_h"] - 1) then
  107.         term.setTextColor(colors.lightGray)
  108.         term.setBackgroundColor(colors.gray)
  109.         term.setCursorPos(tButton["b1_x"]+1,tButton["b1_y"]+tButton["b1_h"]-2)
  110.         print("                  ")
  111.         term.setCursorPos(tButton["b1_x"]+1,tButton["b1_y"]+tButton["b1_h"]-2)
  112.         userInput = read()
  113.         redraw()
  114.       elseif X >= tButton["b2_x"] and X <= (tButton["b2_x"] + tButton["b2_w"] - 1) and Y >= tButton["b2_y"] and Y <= (tButton["b2_y"] + tButton["b2_h"] - 1) then
  115.         passInputN = ""
  116.         term.setTextColor(colors.lightGray)
  117.         term.setBackgroundColor(colors.gray)
  118.         term.setCursorPos(tButton["b2_x"]+1,tButton["b2_y"]+tButton["b2_h"]-2)
  119.         print("                  ")
  120.         term.setCursorPos(tButton["b2_x"]+1,tButton["b2_y"]+tButton["b2_h"]-2)
  121.         passInput = read("*")
  122.         for i=1,#passInput do
  123.           passInputN = passInputN .. "*"
  124.         end
  125.         redraw()
  126.       elseif X >= tButton["b3_x"] and X <= (tButton["b3_x"] + tButton["b3_w"] - 1) and Y >= tButton["b3_y"] and Y <= (tButton["b3_y"] + tButton["b3_h"] - 1) then
  127.         local bReturned = checkCreds()
  128.         if bReturned == true then
  129.           dispSuccess()
  130.         else
  131.           dispFailure()
  132.           redraw()
  133.         end
  134.       end
  135.     end
  136.   end
  137. end
  138.  
  139. term.setBackgroundColor(colors.black)
  140. term.clear()
  141. term.setCursorPos(1,1)
  142. term.setTextColor(colors.yellow)
  143. print(os.version())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement