Thomas9666

[Lua] server usercheck

Apr 3rd, 2018
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. os.loadAPI("/api/tom")
  2. tom.gui()
  3. tom.header("SERVER ACTIVE")
  4. modem = peripheral.wrap("top")
  5. serverchan = 3
  6. modem.open(serverchan)
  7.  
  8. function split(str, pat)
  9. out = {}
  10. for match in (str..pat):gmatch("(.-)"..pat) do
  11. table.insert(out, match)
  12. end
  13. return out
  14. end
  15.  
  16. function readData(input)
  17. t = split(input, "!")
  18. incominguser = t[1]
  19. incominghash = t[2]
  20. incomingpass = t[3]
  21. end
  22.  
  23. local function send(message, whoto)
  24. modem.transmit(whoto, serverchan, message)
  25. end
  26.  
  27. local event, side, recchan, repchan, mess, dist = os.pullEvent("modem_message")
  28. fullstr = mess
  29. readData(fullstr)
  30.  
  31. usercheck = fs.isDir("/users/"..incominguser)
  32. hashcheck = fs.exists("/users/"..incominguser.."/"..incominghash)
  33. passfile = io.open("/users/"..incominguser.."/"..incominghash,"r")
  34. passwd = passfile:read()
  35.  
  36. if usercheck == false then
  37. send("erroruser", repchan)
  38. sleep(1)
  39. tom.gui()
  40. tom.header("User doesn't exist")
  41. sleep(1)
  42. os.reboot()
  43. else
  44. if hashcheck == false then
  45. send("errorhash", repchan)
  46. sleep(1)
  47. tom.gui()
  48. tom.header("Hash incorrect")
  49. sleep(1)
  50. os.reboot()
  51. else
  52. if incomingpass ~= passwd then
  53. send("errorpass", repchan)
  54. sleep(1)
  55. tom.gui()
  56. tom.header("Second Factor password incorrect")
  57. sleep(1)
  58. os.reboot()
  59. elseif incomingpass == passwd then
  60. send("permit", repchan)
  61. sleep(1)
  62. tom.gui()
  63. tom.header("Access granted for " .. incominguser)
  64. sleep(1)
  65. os.reboot()
  66. end
  67. end
  68. end
Add Comment
Please, Sign In to add comment