LeslieCraft

[HUN] MC CC Tekkit, Login system

Oct 15th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.41 KB | None | 0 0
  1. --[[
  2.             ----------> Beléptető rendszer <----------
  3.  
  4. Beléptető rendszer. Előszőr root felhasználónévvel és root jelszóval tudtok belépni.
  5. Ezután tudtok felhasználókat, illetve admin jogokkal rendelkező felhasználókat létrehozni.
  6.  
  7. Egyenlőre egy ajtó nyitási funkció van beprogramozva. Ezt bármire kicserélhetitek.
  8. Erre rákeresve: function Choice1()
  9. Itt találhatjátok az 1. menüpont funkcióhívását. A Choice1 re újra rákeresve a menüt tudjátok átírni.
  10.  
  11. A script szabadon másólható, illetve módosítható, amennyiben az eredeti részt csak kommentezitek és az eredeti
  12. tulaját feltüntetitek. Jelen esetben Matteo Delfavero
  13.  
  14. Használjátok sok sikerrel. Bármi kérdésetek van itt feltehetitek: matteo.delfaveroKUKACgmail.com
  15.  
  16. A jelszavakat 32 bites hash eléssel menti, terminate-elni nem lehet a futó programot, csak újra indítani
  17. a ctrl+r el.
  18.  
  19.  
  20. ui.: A Script csak egy része van commentezve. Hamarosan kész lesz.
  21. 2013.07.18
  22.  
  23. 2017.10.17
  24. -debug funkcio berakva /alapértelmezetten falsra van állítva
  25. -bugfix: ha adminként jelentkeztél be nem írta ki, hogy admin vagy. javítva-
  26. -Menü lista balra igazítva (jobb megjelenítés)
  27.  
  28. ]]--
  29.  
  30. inMainMenuA = false
  31. inMainMenuU = false
  32. DebugMode = false
  33. local termWidth, termHeight = term.getSize()
  34. local selectedItem = 1
  35. username = -1
  36. passworld = -1
  37. rsout1 = "left"
  38. rsout2 = "right"
  39. local pullEvent = os.pullEvent      -- Anti terminate
  40. os.pullEvent = os.pullEventRaw      -- Anti terminate
  41.  
  42.  
  43. function debug(...)
  44.     if DebugMode then print("Debug: " .. tostring(...)) sleep(.25) end
  45. end
  46.  
  47. function StringHash(text)
  48.   local counter = 1
  49.   local len = string.len(text)
  50.   for i = 1, len, 3 do
  51.     counter = math.fmod(counter*8161, 4294967279) +
  52.       (string.byte(text,i)*16776193) +
  53.       ((string.byte(text,i+1) or (len-i+256))*8372226) +
  54.       ((string.byte(text,i+2) or (len-i+256))*3932164)
  55.   end
  56.   return math.fmod(counter, 4294967291)
  57. end
  58.  
  59. function InstallDatabase()                      --Adatbázis mappa létrehozása
  60.     if not fs.exists("Database") then           --Ellenőrzi, hogy létezik-e a mappa
  61.         fs.makeDir("Database")                  --Létrehozza a mappát
  62.         local file = fs.open("Database/root.dat", "w")  --Létrehoz egy root felhasználót tartalmazó file-t
  63.         file.writeLine(tostring(StringHash("root")))                    --Beleírja a root jelszavat
  64.         file.writeLine(tostring(StringHash("true")))                    --Adminra állítja
  65.         file.close()                            --Bezárja a file-t
  66.         return false                            --Igaz értékkel tér vissza a functio
  67.     else
  68.         return true     --Már létre van hozva a mappa ezért false értékkel tér vissza, tehát nem volt telepítés
  69.     end
  70. end
  71.  
  72. function rootPass()
  73.     local file = fs.open("Database/root.dat", "r")
  74.     debug(file)
  75.     local rootPass = file.readLine()
  76.     debug(rootPass)
  77.     local rootAdmin = file.readLine()
  78.     debug(rootAdmin)
  79.     file.close()
  80.     if rootPass == tostring(StringHash("root")) then            --Ha a root jelszava root akkor igaz értékkel tér vissza
  81.         return true                             --Ez kérőbb lesz érdekes
  82.     else
  83.         return false
  84.     end
  85. end
  86.  
  87. function IsAdmin(username)                                          --Ellenőrzi, hogy a felhasználónak vannak-e root azaz admin jogosúltságai
  88.     local file = fs.open("Database/"..username..".dat", "r")
  89.     debug(file)
  90.     local ReadedPass = file.readLine()
  91.     debug(ReadedPass)
  92.     local ReadedAdmin = file.readLine()
  93.     debug(ReadedAdmin)
  94.     file.close()
  95.     if ReadedAdmin == tostring(StringHash("true")) then
  96.         return true
  97.     else
  98.         return false
  99.     end
  100. end
  101.  
  102. function rootChange()
  103.     if rootPass() then
  104.         centerText("-----> Root jelszo megvaltoztatasa <-----")
  105.         print("")
  106.         write("Uj root jelszo: ")
  107.         local rootpass1 = read("x")
  108.         write("Uj root jelszo megegyszer: ")
  109.         local rootpass2 = read("x")
  110.         if rootpass1 == "root" then
  111.             cls()
  112.             centerText("Nem lehet ujra root a jelszo")
  113.             sleep(3)
  114.             return rootChange()
  115.         end
  116.         if rootpass1 == rootpass2 then
  117.             local file = fs.open("Database/root.dat", "w")
  118.             file.writeLine(tostring(StringHash(rootpass2)))
  119.             file.writeLine(tostring(StringHash("true")))
  120.             file.close()
  121.             print("Root jelszo frissitese....")
  122.             sleep(2)
  123.             return true
  124.         else
  125.             print("A ket jelszo nem egyezik")
  126.             sleep(3)
  127.             return rootChange()
  128.         end
  129.     end
  130. end
  131.  
  132. function centerText(text)
  133.     local x,y = term.getSize()
  134.     local x2,y2 = term.getCursorPos()
  135.     term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
  136.     print(text)
  137. end
  138.  
  139. function UserAdd()
  140.     cls()
  141.     centerText("-----> Regisztracio <-----")
  142.     print("")
  143.     write("Felhasznalonev: ")
  144.     local username = read()
  145.     print("")
  146.     write("Jelszo: ")
  147.     local passwd1 = read("x")
  148.     write("Jelszo megerositese: ")
  149.     local passwd2 = read("x")
  150.     write("A felhasznalonak root jogai vannak? i/n: ")
  151.     local Admin = read()
  152.    
  153.     if Admin == "i" or Admin == "I" then
  154.         AdminJog = "true"
  155.     elseif Admin == "n" or Admin == "N" then
  156.         AdminJog = "false"
  157.     else
  158.         print("Helytelen válasz i/n !")
  159.         sleep(3)
  160.         return UserAdd()
  161.     end
  162.    
  163.     if passwd1 ~= passwd2 then
  164.         print("A ket jelszo nem egyezik")
  165.         sleep(3)
  166.         return UserAdd()
  167.     end
  168.    
  169.     if not InstallDatabase() then
  170.         cls()
  171.         print("Nem lehetett létrehozni")
  172.         read("")
  173.         return main()
  174.     end
  175.    
  176.     if fs.exists("Database/" .. username ..".dat") then
  177.         cls()
  178.         print("Van mar ilyen felhasznalo")
  179.         read("")
  180.         return main()
  181.     end
  182.    
  183.     local file = fs.open("Database/" .. username ..".dat", "w")
  184.     file.writeLine(tostring(StringHash(passwd1)))
  185.     file.writeLine(tostring(StringHash(AdminJog)))
  186.     file.close()
  187.     return menu()
  188. end
  189.  
  190. function cls()
  191.     term.clear()
  192.     term.setCursorPos(1,1)
  193. end
  194.  
  195. function NoUser()
  196.     cls()
  197.     print("Nincs ilyen felhasznalo")
  198.     read("")
  199.     return main()
  200. end
  201.  
  202. function Acces(user, pass)
  203.     if fs.exists("Database/"..user..".dat") then
  204.         local file = fs.open("Database/"..user..".dat", "r")
  205.         debug(file)
  206.         local ReadedPass = file.readLine()
  207.         adminUser = file.readLine()
  208.         debug(adminUser)
  209.         file.close()
  210.         if ReadedPass == tostring(StringHash(pass)) then
  211.             return true
  212.         else
  213.             return false
  214.         end
  215.     else
  216.         return NoUser()
  217.     end
  218. end
  219.  
  220. function AccessDenied()
  221.     cls()
  222.     print("Felhasznalonev/jelszo nem eggyezik")
  223.     read("")
  224.     return main()
  225. end
  226.  
  227. function AccessEnable()
  228.     rootChange()
  229.     print("Debug mauin")
  230.     return menu()
  231. end
  232.  
  233. function main()
  234.     InstallDatabase()
  235.     cls()
  236.     centerText("-----> Bejelentkezes <-----")
  237.     print("")
  238.     write("Felhasznalonev: ")
  239.     username = read()
  240.     print("")
  241.     write("Jelszo: ")
  242.     passworld = read("x")
  243.     if Acces(username, passworld) then
  244.         return AccessEnable()
  245.     else
  246.         return AccessDenied()
  247.     end
  248. end
  249.  
  250. function printMenu ( menu, admin )
  251.     if admin then
  252.         centerText("Udv admin: " .. username)
  253.     else
  254.         centerText("Udv user: " .. username)
  255.     end
  256.    
  257.     for i = 1, #menu do
  258.         if i == selectedItem then
  259.           term.setCursorPos(15,(i+5))
  260.           print(">> "..menu[i].text)
  261.         else
  262.           term.setCursorPos(15,(i+5))
  263.           print("   "..menu[i].text)
  264.         end
  265.     end
  266. end
  267.  
  268. function onKeyPressed( key, menu )
  269. --  if key == keys.enter then
  270.     if key == 28 then
  271.         onItemSelected(menu)
  272.     elseif key == 200 then
  273. --  elseif key == keys.up then
  274.         if selectedItem > 1 then
  275.             selectedItem = selectedItem - 1
  276.         end
  277. --  elseif key == keys.down then
  278.     elseif key == 208 then
  279.         if selectedItem < #menu then
  280.             selectedItem = selectedItem +1
  281.         end
  282.     end
  283. end
  284.  
  285. function onItemSelected(menu)
  286.     menu[selectedItem].handler()
  287. end
  288.  
  289. function timerAjto(sec)
  290.     while sec ~= 0 do
  291.         cls()
  292.         centerText("Ajtok zarasa " .. sec .. "-mp mulva.")
  293.         sec = sec-1
  294.         debug("Counter down -1: ", sec)
  295.         sleep(1)
  296.     end
  297. end
  298.  
  299. function timer(sec)
  300.     while sec ~= 0 do
  301.         write(sec)
  302.         sec = sec-1
  303.         sleep(1)
  304.     end
  305. end
  306.  
  307. function Choice1()      --Ajtó nyitás
  308.     cls()
  309.     redstone.setOutput(rsout1, true)
  310.     debug("redstone.setOutput(rsout1, true)")
  311.     redstone.setOutput(rsout2, true)
  312.     debug("redstone.setOutput(rsout2, true)")
  313.     timerAjto(6)
  314.     redstone.setOutput(rsout1, false)
  315.     debug("redstone.setOutput(rsout1, false)")
  316.     redstone.setOutput(rsout2, false)
  317.     debug("redstone.setOutput(rsout2, false)")
  318.     return menu()
  319. end
  320.  
  321. function Choice2()      --Új regisztráció
  322.     UserAdd()
  323. end
  324.  
  325. function Choice3()
  326.     cls()
  327.     centerText("-----> Jelszo csere <-----")
  328.     print("")
  329.     write("Felhasznalonev: ")
  330.     local ExchangeUserPass = read()
  331.     print("Felhasznalo keresese...")
  332.     sleep(2)
  333.     if fs.exists("Database/"..ExchangeUserPass..".dat") then
  334.         print("Felhasznalo megtalalva: " .. ExchangeUserPass)
  335.         local file = fs.open("Database/"..ExchangeUserPass..".dat", "r")
  336.         local ReadedPass = file.readLine()
  337.         local ReadedAdmin = file.readLine()
  338.         file.close()
  339.        
  340.         write("Uj jelszo: ")
  341.         local Passwd1 = read("x")
  342.         write("Jelszo megegyszer: ")
  343.         local Passwd2 = read("x")
  344.         if Passwd1 == Passwd2 then
  345.             local file = fs.open("Database/"..ExchangeUserPass..".dat", "w")
  346.             file.writeLine(tostring(StringHash(Passwd1)))
  347.             file.writeLine(tostring(StringHash(ReadedAdmin)))
  348.             file.close()
  349.             print("Jelszo frissitese...")
  350.             sleep(1)
  351.             print("Frissites sikeres a/az " .. ExchangeUserPass .. " felhasznalonal")
  352.             sleep(3)
  353.             return menuA()
  354.         else
  355.             print("A ket jelszo nem egyezik!!!")
  356.             sleep(3)
  357.             return Choice3()
  358.         end
  359.     else
  360.         print("Nem talalhato ilyen felhasznalo: "  .. ExchangeUserPass)
  361.     end
  362. end
  363.  
  364. function Choice4()
  365.     cls()
  366.     centerText("-----> Jelszo csere <-----")
  367.     print("")
  368.     write("Jelenlegi jelszavad: ")
  369.     local NowPass = read("x")
  370.     local file = fs.open("Database/"..username..".dat", "r")
  371.     local NowReadedPass = file.readLine()
  372.     file.close()
  373.     if NowReadedPass == tostring(StringHash(NowPass)) then
  374.         write("Uj jelszo megadasa: ")
  375.         local NewPasswd1 = read("x")
  376.         write("Jelszo megegyszer: ")
  377.         local NewPasswd2 = read("x")
  378.         if NewPasswd1 == NewPasswd2 then
  379.             local file = fs.open("Database/"..username..".dat", "w")
  380.             file.writeLine(tostring(StringHash(NewPasswd2)))
  381.             file.writeLine(tostring(StringHash("false")))
  382.             file.close()
  383.             print("Jelszo frissitese....")
  384.             sleep(2)
  385.             print("Kesz!")
  386.             sleep(.5)
  387.             return menu()
  388.         else
  389.             print("A ket jelszo nem eggyezik!!")
  390.             sleep(3)
  391.             cls()
  392.             return Choice4()
  393.         end
  394.     else
  395.         print("A megadott jelszavad nem")
  396.         print("eggyezik a tarolt jelszavaddal.")
  397.         sleep(4)
  398.         return menu()
  399.     end
  400. end
  401.  
  402. function Choise5()
  403.     cls()
  404.     centerText("-----> felhasznalo torlese <-----")
  405.     print("")
  406.     write("Felhasznalonev: ")
  407.     local DeleteUser = read()
  408.     print("Felhasznalo keresese...")
  409.     sleep(2)
  410.     if fs.exists("Database/"..DeleteUser..".dat") then
  411.         print("Felhasznalo megtalalva.")
  412.         print("Biztosan torolni szeretned a/az " .. DeleteUser .. " felhasznalot? i/n")
  413.         local Delete = read()
  414.         if Delete == "i" or Delete == "I" then
  415.             fs.delete("Database/"..DeleteUser..".dat")
  416.             print("Torles...")
  417.             sleep(1)
  418.             if not fs.exists("Database/"..DeleteUser..".dat") then
  419.                 print("Sikeresen torolted a/az " .. DeleteUser .. " felhasznalot.")
  420.                 sleep(3)
  421.                 return menu()
  422.             else
  423.                 print("ERROR FELHASZNALO NEM TOROLHETO")
  424.                 sleep(3)
  425.                 return menu()
  426.             end
  427.         elseif Delete == "n" or Delete == "N" then
  428.             return menu()
  429.         else
  430.             print("Igen vagy nem?! i/n")
  431.             sleep(3)
  432.             return Choise5()
  433.         end
  434.     else
  435.         print("Felhasznalo nem talalhato")
  436.         sleep(3)
  437.         return menu()
  438.     end
  439. end
  440.  
  441. function Choise6()
  442.     cls()
  443.     centerText("-----> Osszes felhasznalo <-----")
  444.     local FileList = fs.list("Database/")
  445.     for _, file in ipairs(FileList) do
  446.         print(file)
  447.     end
  448.    
  449.     read("")
  450.     return menu()
  451. end
  452.  
  453. function Exit()         --Kijelentkezés
  454.     inMainMenuA = false
  455.     inMainMenuU = false
  456.     main()
  457. end
  458.  
  459.  
  460. mainMenuA = {
  461.     [1] = { text = "Ajtok nyitasa", handler = Choice1 },
  462.     [2] = { text = "Uj regisztracio", handler = Choice2 },
  463.     [3] = { text = "Jelszo csere", handler = Choice3 },
  464.     [4] = { text = "Felhasznalo torlese", handler = Choise5 },
  465.     [5] = { text = "Osszes felhasznalo", handler = Choise6 },
  466.     [6] = { text = "Log out", handler = Exit }
  467. }
  468.  
  469. mainMenuU = {
  470.     [1] = { text = "Ajtok nyitasa", handler = Choice1 },
  471.     [2] = { text = "Sajat jelszo cere", handler = Choice4 },
  472.     [3] = { text = "Log out", handler = Exit }
  473. }
  474.  
  475. function menu()
  476.     debug(username)
  477.     if IsAdmin(username) then
  478.         selectedItem = 1
  479.         inMainMenuA = true
  480.         inMainMenuU = false
  481.         return menuA()
  482.     else
  483.         selectedItem = 1
  484.         inMainMenuA = false
  485.         inMainMenuU = true
  486.         return menuU()
  487.     end
  488. end
  489.  
  490. function menuA()
  491.     while inMainMenuA do
  492.         cls()
  493.         printMenu(mainMenuA, true)
  494.         event, key = os.pullEvent("key")
  495.         onKeyPressed(key, mainMenuA)
  496.     end
  497. end
  498.  
  499. function menuU()
  500.     while inMainMenuU do
  501.         cls()
  502.         printMenu(mainMenuU, false)
  503.         event, key = os.pullEvent("key")
  504.         onKeyPressed(key, mainMenuU)
  505.     end
  506. end
  507.  
  508.  
  509. main()
Add Comment
Please, Sign In to add comment