Theshadow989

[xOS] Add Accounts

Jan 8th, 2016
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.40 KB | None | 0 0
  1. --[[
  2. Add Accounts File
  3. Written by TheShadow989
  4. ]]--
  5.  
  6. os.pullEvent = os.pullEventRaw
  7. os.loadAPI("xos/api/sha256")
  8.  
  9. local verNumber = "Alpha 1.24"
  10. local x = term.getSize()
  11.  
  12. rRead = fs.open("xos/.usertable", "r")
  13. users = textutils.unserialize(rRead.readAll())
  14. rRead.close()
  15. cu = tonumber(users[1])
  16. cs = tonumber(users[cu+1])
  17. cp = tonumber(users[cu+2])
  18.  
  19. local function cPrint(string)
  20.     x, _ = term.getSize()
  21.     _, y = term.getCursorPos()
  22.     term.setCursorPos((x-#string)/2,y)
  23.     textutils.slowPrint(string)
  24.  
  25. end
  26.  
  27. local function kPrint(string)
  28.     x, _ = term.getSize()
  29.     _, y = term.getCursorPos()
  30.     term.setCursorPos((x-#string)/2,y)
  31.     print(string)
  32. end
  33.  
  34. local function errormsg()
  35.     term.clear()
  36.     term.setCursorPos(1,19)
  37.     term.write("xOS "..verNumber.." by TheShadow989")
  38.     term.setCursorPos(1,3)
  39.     kPrint("Create Account")
  40.     term.setCursorPos(11,8)
  41. end
  42.  
  43. term.clear()
  44. term.setCursorPos(1,19)
  45.  
  46. term.write("xOS "..verNumber.." by TheShadow989")
  47.  
  48. term.setCursorPos(1,3)
  49. cPrint("Create Account")
  50. sleep(2)
  51.  
  52. while true do
  53.     term.setCursorPos(17,8)
  54.     write("Username: ")
  55.     newuser = read()
  56.     userlenght = string.len(newuser)
  57.  
  58.     if userlenght >= 10 then
  59.         errormsg()
  60.         term.setTextColor( colors.red )
  61.         kPrint("Username must be between 1-9 characters!")
  62.         term.setTextColor( colors.white )
  63.         sleep(3)
  64.         errormsg()
  65.     else
  66.         break
  67.     end
  68. end
  69.  
  70.  
  71. while true do
  72.     term.setCursorPos(17,8)
  73.     write("Username: "..newuser)   
  74.  
  75.     term.setCursorPos(17,10)
  76.     write("Password: ")
  77.     newpass = read('*')
  78.  
  79.     term.setCursorPos(17,12)
  80.     write("Re-enter Password: ")
  81.     newpass2 = read('*')
  82.  
  83.     if newpass ~= newpass2 then
  84.         errormsg()
  85.         term.setTextColor( colors.red )
  86.         kPrint("Passwords entered do not match!")
  87.         term.setTextColor( colors.white )
  88.         sleep(3)
  89.         errormsg()
  90.     else
  91.         break
  92.     end
  93. end
  94.  
  95. newseclvl = "1"
  96.  
  97. if users[5] == nil then
  98.     users[5] = newuser
  99.     users[6] = newseclvl
  100.     users[7] = sha256.sha256(newpass)
  101. elseif users[8] == nil then
  102.     users[8] = newuser
  103.     users[9] = newseclvl
  104.     users[10] = sha256.sha256(newpass)
  105. elseif users[11] == nil then
  106.     users[11] = newuser
  107.     users[12] = newseclvl
  108.     users[13] = sha256.sha256(newpass)
  109. end
  110.  
  111. rWrite = fs.open("xos/.usertable", "w")
  112. rWrite.write(textutils.serialize(users))
  113. rWrite.close()
  114.  
  115. term.clear()
  116. term.setTextColor(colors.green)
  117. term.setCursorPos(11,8)
  118. kPrint("Account Created, Rebooting!")
  119. sleep(3)
  120. os.reboot()
Add Comment
Please, Sign In to add comment