Advertisement
CharlieOS

Login

Jun 26th, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.04 KB | None | 0 0
  1. os.pullEvent = os.pullEventRaw
  2. state = 0
  3. username = true
  4. password = false
  5.  
  6.  
  7. --Function
  8. local readN = function(len, replaceChar)
  9.       len = len or 12
  10.       local input=""
  11.       local key = 0
  12.       term.setCursorBlink(true)
  13.       repeat
  14.         local e,p1= os.pullEvent()
  15.         if e=="char" then
  16.           if #input < len then
  17.             input = input .. p1
  18.             term.write(replaceChar or p1)
  19.           end
  20.         elseif e=="key" and p1==keys.backspace and #input > 0 then
  21.           input = input:sub(1,#input-1)
  22.           local x,y = term.getCursorPos()
  23.           term.setCursorPos(x-1,y)
  24.           term.write(" ")
  25.           term.setCursorPos(x-1,y)
  26.         end
  27.       until p1==keys.enter
  28.       term.setCursorBlink(false)
  29.       return input
  30.     end
  31.  
  32. drawLogin = function()
  33.     term.setBackgroundColor(colors.cyan)
  34.     clear()
  35.     image = paintutils.loadImage("/system/res/dUser")
  36.     paintutils.drawImage(image, 15,4)
  37.     term.setCursorPos(25, 5)
  38.     term.setBackgroundColor(colors.white)
  39.     term.setTextColor(colors.lightGray)
  40.     term.write("Username")
  41.     term.setCursorPos(25, 7)
  42.     term.setBackgroundColor(colors.lightGray)
  43.     term.setTextColor(colors.gray)
  44.     term.write("Password")
  45.     term.setCursorPos(47,18)
  46.     term.setTextColor(colors.white)
  47.     term.setBackgroundColor(colors.red)
  48.     print("O @")
  49.     term.setCursorPos(48,18)
  50.     term.setTextColor(colors.gray)
  51.     print("|")
  52. end
  53.  
  54. login = function()
  55.     while username == true and state == 0 do
  56.         e, button, x, y = os.pullEvent()
  57.         if username == true and e == "mouse_up" and button == 1 and x >= 25 and x <= 36 and y == 5 then
  58.             paintutils.drawLine(25,5, 36, 5, colors.white)
  59.             term.setTextColor(colors.black)
  60.             term.setCursorPos(25,5)
  61.             name = readN()
  62.             userN = name
  63.             if userN == userN then
  64.                 file = fs.open("/system/users/user_profile", "r")
  65.             if file.readLine() == userN then
  66.                 state = 1
  67.                 username = false
  68.                 password = true
  69.             else
  70.                 file.close()
  71.                 term.setTextColor(colors.red)
  72.                 term.setBackgroundColor(colors.cyan)
  73.                 term.setCursorPos(25,8)
  74.                 print("Unknown Username:" .. userN)
  75.                 sleep(1)
  76.                 paintutils.drawLine(25,8, 51,8,colors.cyan)
  77.             end
  78.             end
  79.         end
  80.     end
  81.     while password == true and state == 1 do
  82.         e, button, x, y = os.pullEvent()
  83.         if password == true and state == 1 then
  84.             term.setCursorBlink(false)
  85.             paintutils.drawLine(25,7, 36,7, colors.white)
  86.             term.setTextColor(colors.black)
  87.             term.setCursorPos(25,7)
  88.             pass = readN(12, "#")
  89.             userP = pass
  90.             if userP == userP then
  91.                 file = fs.open("/system/users/user_profile", "r")
  92.                 file.readLine()
  93.             if file.readLine() == userP then
  94.                 file.close()
  95.                 shell.run("/system/firmware")
  96.             else
  97.                 file.close()
  98.                 term.setTextColor(colors.red)
  99.                 term.setBackgroundColor(colors.cyan)
  100.                 term.setCursorPos(25,8)
  101.                 print("Invalid Password!")
  102.                 sleep(1)
  103.                 paintutils.drawLine(25,8, 51,8,colors.cyan)
  104.             end
  105.             end
  106.             end
  107.             end
  108.     end
  109.  
  110. clear = function()
  111.     term.clear()
  112.     term.setCursorPos(1,1)
  113. end
  114.  
  115. start = function()
  116.     state = 0
  117.     clear()
  118.     drawLogin()
  119.     login()
  120. end
  121.  
  122. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement