Advertisement
breadfishsticks

Startup.lua / Passwords

May 19th, 2024 (edited)
958
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.14 KB | Gaming | 0 0
  1. local AdminUsers = {"bob", "breadfishsticks", "legomasterdaniel"}
  2.  
  3. local pullEvent = os.pullEvent
  4. -- os.pullEvent = os.pullEventRaw
  5.  
  6. local Running = true
  7.  
  8. term.clear()
  9. term.setCursorPos(1, 1)
  10.  
  11. local function AdminConfirm(UserInfo)
  12.         write("Password: ")
  13.         local Password = read("*")
  14.    
  15.     return tostring(UserInfo["Password"]) == tostring(Password)
  16. end
  17. end
  18.  
  19. local function LoggedInFunction(UserInfo)
  20.     for i, AdminUser in pairs(AdminUsers) do
  21.     print(AdminUser, UserInfo["Username"])
  22.         if tostring(UserInfo["Username"]) == AdminUser then
  23.             while Running do
  24.             print("What can i do for you?")
  25.             print("")
  26.             print("Exit out of the program. (EXIT)")
  27.             print("Logout. (LOGOUT)")
  28.             print("Delete a account. (DELETE)")
  29.             print("Change a account's password. (CHANGE-PASSWORD)")
  30.            
  31.             local Answer = nil
  32.             repeat
  33.                 Answer = read()
  34.             until Answer ~= nil
  35.             Answer = string.lower(Answer)
  36.             if Answer == "exit" then
  37.                 local Password = AdminConfirm(UserInfo)
  38.                
  39.                 if Password == true then
  40.                
  41.                 print("Goodbye.")
  42.                 sleep(2)
  43.                 Running = false
  44.                
  45.                 else
  46.                
  47.                     print("Incorrect, I am sorry.")
  48.                
  49.                 end
  50.             elseif Answer == "logout" then
  51.                 print("Thank you.")
  52.                 sleep(2)
  53.                 os.reboot()
  54.             elseif Answer == "delete" then
  55.                 local User = nil
  56.                 repeat
  57.                     write("Account Username to delete: ")
  58.                     User = tostring(read())
  59.                 until User ~= nil
  60.                 local Password = AdminConfirm(UserInfo)
  61.                  
  62.            
  63.             end
  64.            
  65.         end
  66.     end
  67. end
  68.  
  69.  
  70.  
  71. while Running do
  72.     local LoggingIn = nil
  73.     local Input = nil
  74.    
  75.     repeat
  76.     write("Login Or Sign-Up? (LOGIN/SIGNUP): ")
  77.     Input = string.lower(read())
  78.    
  79.     if Input == "login" then
  80.         print("")
  81.         print("Selected mode: LOGIN")
  82.        
  83.         Username = nil
  84.        
  85.         repeat
  86.             write("Username: ")
  87.             Username = read()
  88.         until Username ~= nil
  89.         local Path = "/Passwords/".. Username
  90.         local File = fs.open(Path .. ".lua", "r")
  91.         if File ~= nil then
  92.             File.close()
  93.             local UserInfo = nil
  94.            
  95.             local Success, Error = pcall(function()
  96.                 UserInfo = require(Path)
  97.             end)
  98.            
  99.             if UserInfo ~= nil then
  100.                 local Password = nil
  101.                 repeat
  102.                     write("Password: ")
  103.                     Password = read("*")
  104.                 until Password ~= nil
  105.                
  106.                 if tostring(UserInfo["Password"]) == tostring(Password) then
  107.                     LoggedInFunction(UserInfo)
  108.                 end
  109.             end
  110.         else
  111.             print("Your account doesnt exist.")
  112.             sleep(3)
  113.             os.reboot()
  114.         end
  115.     elseif Input == "signup" then
  116.         local Username = nil
  117.        
  118.         repeat
  119.             write("Username: ")
  120.             Username = read()
  121.         until Username ~= nil
  122.        
  123.         local Path = "/Passwords/".. Username .. ".lua"
  124.         if fs.exists(Path) then
  125.             print("You already signed up.")
  126.             sleep(3)
  127.             os.reboot()
  128.         else
  129.             local Password = nil
  130.            
  131.             repeat
  132.                 write("Password: ")
  133.                 Password = read("*")
  134.             until Password ~= nil
  135.            
  136.             local File = fs.open(Path, "w")
  137.             File.write('return { Username = "' .. Username .. '", Password = "' .. Password .. '" }')
  138.             File.close()
  139.            
  140.             print("Account made.")
  141.         end
  142.     else
  143.         print("Invalid Response.")
  144.         sleep(3)
  145.         os.reboot()
  146.     end
  147.    
  148.     until Input ~= nil
  149.    
  150. end
Tags: cc:tweaked
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement