jesusthekiller

jLogin startup

Jun 22nd, 2013
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.77 KB | None | 0 0
  1. --[[
  2.     Project info:
  3.    
  4.     Name: jLogin
  5.     Creator: Jesusthekiller
  6.     Language: Lua (CC)
  7.     Website: None
  8.     License: GNU GPL
  9.         License file can be fount at www.jesusthekiller.com/license-gpl.html
  10.  
  11.     Version: 1.0
  12. ]]--
  13.  
  14. --[[
  15.     Changelog:
  16.       1.0:
  17.         Initial Release
  18. ]]--
  19.  
  20. --[[
  21.     LICENSE:
  22.    
  23.     jLogin
  24.     Copyright (c) 2013 Jesusthekiller
  25.  
  26.     This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  27.  
  28.     This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  29.  
  30.     See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
  31. ]]--
  32.  
  33. -- Prevent CTRL+T
  34. local oev = os.pullEvent
  35. os.pullEvent = os.pullEventRaw
  36.  
  37. -- Get sha256 API
  38. if not fs.exists("sha256") then
  39.     assert(http, "HTTP API required to download dependencies!")
  40.     shell.run("pastebin", "get", "8K9hVgXV", "sha256")
  41. end
  42.  
  43. if not sha256 then
  44.     os.loadAPI("sha256")
  45. end
  46.  
  47. -- Create command
  48. if not fs.isDir("login") then -- Remove if not dir
  49.     fs.delete("login")
  50. end
  51.  
  52. if not fs.exists("login") then -- Create dir
  53.     fs.makeDir("login")
  54. end
  55.  
  56. if not fs.exists("login/login") then -- Download login cmd
  57.     assert(http, "HTTP API required to download dependencies!")
  58.     shell.run("pastebin", "get", "pRan4MNW", "login/login")
  59. end
  60.  
  61. shell.setPath("/login:"..shell.path()) -- Set path
  62.  
  63. -- Login screen
  64. term.setBackgroundColor(colors.black)
  65. term.setTextColor(colors.white)
  66. term.clear()
  67. term.setCursorPos(1, 1)
  68.  
  69. if not fs.exists("login_users") then -- Check for file
  70.     print("No users added! Do login adduser <login> <password>")
  71.     return
  72. end
  73.  
  74. local f = fs.open("login_users", "r") or os.reboot() -- Open users file
  75. local t = {}
  76.  
  77. for token in string.gmatch(f.readAll(), "[^\n]+") do -- Users file to table
  78.     table.insert(t, token)
  79. end
  80.  
  81. f.close()
  82.  
  83. if #t < 2 or #t % 2 == 1 then -- Check for corrupted file
  84.     fs.delete("login_users")
  85.     print("login_users file is empty or corrupted! File deleted!")
  86.     print("Press any key...")
  87.     coroutine.yield()
  88.     os.pullEvent("key")
  89.     os.reboot()
  90. end
  91.  
  92. local counter = 0
  93.  
  94. while true do -- Login loop
  95.     term.setBackgroundColor(colors.black)
  96.     term.setTextColor(colors.white)
  97.     term.clear()
  98.     term.setCursorPos(1, 1)
  99.    
  100.     if counter % 3 == 0 and counter ~= 0 then -- 30s sleep every 3 fails
  101.         print("Exceeded maximum fail count! You have failed "..counter.." times!")
  102.         for i = counter * 5, 1, -1 do
  103.             term.setCursorPos(1, 3)
  104.             term.clearLine()
  105.             write("You have to wait "..i..((i == 1) and " second" or " seconds"))
  106.             sleep(1)
  107.         end
  108.        
  109.         term.setBackgroundColor(colors.black)
  110.         term.setTextColor(colors.white)
  111.         term.clear()
  112.         term.setCursorPos(1, 1)
  113.     end
  114.    
  115.     if counter == 0 then
  116.         print("This computer is locked!")
  117.     end
  118.    
  119.     write("Login: ")
  120.     local login = read():gsub("%s", "") -- Remove white chars
  121.    
  122.     write("Password: ")
  123.     local password = read(" ") -- Read w/o any characters shown
  124.    
  125.     local logged
  126.    
  127.     for i = 1, #t, 2 do -- Check pass
  128.         if t[i]:lower() == login:lower() then
  129.             if t[i+1] == sha256.sha256(password) then
  130.                 logged = true
  131.                 term.setBackgroundColor(colors.black)
  132.                 term.setTextColor(colors.white)
  133.                 term.clear()
  134.                 term.setCursorPos(1, 1)
  135.                 print("Welcome, "..login)
  136.                 break
  137.             end
  138.         end
  139.     end
  140.    
  141.     if logged then
  142.         break
  143.     else
  144.         print("Wrong login and password combo!")
  145.         sleep(1) -- For no brute force
  146.         counter = counter + 1
  147.     end
  148. end
  149.  
  150. -- Unload APIs
  151. os.unloadAPI("sha256")
  152.  
  153. -- Restore os.pullEvent
  154. os.pullEvent = oev
Advertisement
Add Comment
Please, Sign In to add comment