Advertisement
CharlieOS

Register

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