Advertisement
VicyX

ComputerCraft FactoryOS

Sep 20th, 2020 (edited)
1,448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.28 KB | None | 0 0
  1. Users = {
  2.     {'VicyX', 'uabitch34'},
  3.     {'test', 'test'}
  4. }
  5. local MasterPass = "password"
  6. local LoginUser
  7. local LoginPass
  8.  
  9. local DoorOpen = false
  10.  
  11. --Create Windows
  12. local winLogin = window.create(term.current(), 1, 1, 50, 30)
  13. local winMenu = window.create(term.current(), 1, 1, 50, 30)
  14. winMenu.setVisible(false)
  15. local winAddUser = window.create(term.current(), 1, 1, 50, 30)
  16. winAddUser.setVisible(false)
  17. local winDelUser = window.create(term.current(), 1, 1, 50, 30)
  18. winDelUser.setVisible(false)
  19. local winListUsers = window.create(term.current(), 1, 1, 50, 30)
  20. winListUsers.setVisible(false)
  21.  
  22. function printLoginArt()
  23.     print("BITCH INC. PRODUCTS")
  24. end
  25.  
  26. function clearAllWindows()
  27.     winLogin.clear()
  28.     winMenu.clear()
  29.     winAddUser.clear()
  30.     winDelUser.clear()
  31.     winListUsers.clear()
  32.     winLogin.setVisible(false)
  33.     winMenu.setVisible(false)
  34.     winAddUser.setVisible(false)
  35.     winDelUser.setVisible(false)
  36.     winListUsers.setVisible(false)
  37. end
  38.  
  39. function listUsers()
  40.     clearAllWindows()
  41.     winListUsers.setVisible(true)
  42.     winListUsers.clear()
  43.  
  44.     print('[[USER LIST]')
  45.     print()
  46.     print()
  47.     print('Select a User:')
  48.     print()
  49.     for i,v in pairs(Users) do
  50.         print("["..tostring(i).."] "..v[1])
  51.     end
  52.     print()
  53.     write('Press ENTER to Continue...')
  54.     local resp = read(" ")
  55. end
  56.  
  57. function delUser()
  58.     clearAllWindows()
  59.     winDelUser.setVisible(true)
  60.     winDelUser.clear()
  61.    
  62.     print('[[DELETE USER]')
  63.     print()
  64.     print()
  65.     print('Select a User:')
  66.     print()
  67.     for i,v in pairs(Users) do
  68.         print("["..tostring(i).."] "..v[1])
  69.     end
  70.     local resp = read()
  71.     if tonumber(resp) then
  72.         if Users[tonumber(resp)] then
  73.             print()
  74.             write(Users[tonumber(resp)][1].." Password OR Master Password: ")
  75.             local inputPass = read("*")
  76.             if inputPass == MasterPass or inputPass == Users[tonumber(resp)][2] then
  77.                 winDelUser.setTextColor(colors.green)
  78.                 write("Successfully Deleted User")
  79.                 winDelUser.setTextColor(colors.white)
  80.                 sleep(2)
  81.                 if Users[tonumber(resp)][1] == LoginUser then
  82.                     table.remove(Users, tonumber(resp))
  83.                     return true
  84.                 end
  85.                 table.remove(Users, tonumber(resp))
  86.             else
  87.                 winDelUser.setTextColor(colors.red)
  88.                 write("Invalid")
  89.                 winDelUser.setTextColor(colors.white)
  90.                 sleep(2)
  91.                 delUser()
  92.             end
  93.         else
  94.             winDelUser.setTextColor(colors.red)
  95.             write("Invalid")
  96.             winDelUser.setTextColor(colors.white)
  97.             sleep(2)
  98.             delUser()
  99.         end
  100.     end
  101. end
  102.  
  103. function addUser()
  104.     clearAllWindows()
  105.     winAddUser.setVisible(true)
  106.     winAddUser.clear()
  107.    
  108.     print('[ADD USER]')
  109.     print()
  110.     print()
  111.     write("Current User Password: ")
  112.     local inputCurPass = read("*")
  113.     write("User Name: ")
  114.     local inputUserName = read()
  115.     write("User Password: ")
  116.     local inputUserPass = read("*")
  117.     write("Confirm User Password: ")
  118.     local inputConfUserPass = read("*")
  119.    
  120.     local Error = false
  121.     if inputCurPass == LoginPass then
  122.         for i,v in pairs(Users) do
  123.             if string.lower(v[1]) == string.lower(inputUserName) then
  124.                 Error = true
  125.             end
  126.         end
  127.         if inputUserPass ~= inputConfUserPass then
  128.             Error = true
  129.         end
  130.     end
  131.    
  132.     if Error == false then
  133.         table.insert(Users, {inputUserName, inputUserPass})
  134.         winAddUser.setTextColor(colors.green)
  135.         write("Successfully added User")
  136.         winAddUser.setTextColor(colors.white)
  137.         sleep(2)
  138.     else
  139.         winAddUser.setTextColor(colors.red)
  140.         write("Invalid")
  141.         winAddUser.setTextColor(colors.white)
  142.         sleep(2)
  143.         addUser()
  144.     end
  145. end
  146.  
  147. function Login()
  148.     clearAllWindows()
  149.     --winLogin.setBackgroundColor(colors.blue)
  150.     winLogin.clear()
  151.     winLogin.setCursorPos(1,1)
  152.     winLogin.setVisible(true)
  153.     winLogin.restoreCursor()
  154.     printLoginArt()
  155.     print()
  156.     print()
  157.     write("Username: ")
  158.     inputUser = read()
  159.     write("Password: ")
  160.     inputPass = read("*")
  161.    
  162.     local Found = false
  163.     for i,v in pairs(Users) do
  164.         if Found == false and inputUser == v[1] and inputPass == v[2] then
  165.             Found = true
  166.             LoginUser = v[1]
  167.             LoginPass = v[2]
  168.             winLogin.setTextColor(colors.green)
  169.             write("Login Successful")
  170.             winLogin.setTextColor(colors.white)
  171.             sleep(2)
  172.             Menu()
  173.         else
  174.             if Found == False then
  175.                 winLogin.setTextColor(colors.red)
  176.                 write("Invalid Login")
  177.                 winLogin.setTextColor(colors.white)
  178.                 sleep(2)
  179.             end
  180.         end
  181.     end
  182. end
  183.  
  184. function Menu()
  185.     clearAllWindows()
  186.     winLogin.setVisible(false)
  187.     local Logout = false
  188.     while Logout == false do
  189.         winMenu.clear()
  190.         winMenu.setVisible(true)
  191.         print('[MENU]')
  192.         print()
  193.         print()
  194.         print("Select an option: ")
  195.         print()
  196.         if redstone.getOutput("right") == false then
  197.             print("[1] Toggle Door [CLOSED]")
  198.         else
  199.             print("[1] Toggle Door [OPEN]")
  200.         end
  201.         print("[2] Create New User")
  202.         print("[3] Delete User")
  203.         print("[4] User List")
  204.         print("[5] Logout")
  205.         print()
  206.         local resp = read()
  207.         if tonumber(resp) then
  208.             if tonumber(resp) == 1 then
  209.                 if DoorOpen == false then
  210.                     redstone.setOutput('right', true)
  211.                     DoorOpen = true
  212.                 else
  213.                     redstone.setOutput('right', false)
  214.                     DoorOpen = false
  215.                 end
  216.             elseif tonumber(resp) == 2 then
  217.                 addUser()
  218.             elseif tonumber(resp) == 3 then
  219.                 local funcResp = delUser()
  220.                 if funcResp == true then
  221.                     Logout = true
  222.                 end
  223.             elseif tonumber(resp) == 4 then
  224.                 listUsers()
  225.             elseif tonumber(resp) == 5 then
  226.                 LoginUser = nil
  227.                 LoginPass = nil
  228.                 Logout = true
  229.             end
  230.         end
  231.     end
  232. end
  233.  
  234. while true do
  235.     sleep(.5)
  236.     Login()
  237. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement