Advertisement
onwardprogress

adminTest

Dec 30th, 2022 (edited)
1,172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.61 KB | Software | 0 0
  1. --This version of the code utilizes a no longer existing crypto library and should not be used.
  2.  
  3. -- The key and IV used for encryption and decryption
  4. local key = "a secret key"
  5. local iv = "an initialization vector"
  6.  
  7. -- The server computer id
  8. local server_id = "2"
  9.  
  10. -- Function to check if a disk is inserted into any of the computer drives
  11. function checkDisk()
  12.     local result = false
  13.     if disk.isPresent("left") and disk.isPresent("right") then
  14.         result = true
  15.     end
  16.     return result
  17. end
  18.  
  19. -- Main program loop
  20. while true do
  21.     -- Prompt the user to insert a blank disk into the left drive and an admin disk into the right drive
  22.     print("Please insert a blank disk into the left drive and an Administrator disk into the right drive.")
  23.     -- Wait for a disk to be inserted into the left drive
  24.     while not checkDisk() do
  25.         sleep(1)
  26.     end
  27.     local mountPath = disk.getMountPath("right")
  28.     if fs.exists(mountPath .. "/user_id.txt") and fs.exists(mountPath .. "/user_pass.txt") then
  29.         -- Open the "id" file on the right disk
  30.         local file = fs.open(mountPath .. "/user_id.txt", "r")
  31.         -- Read the contents of the file
  32.         local admin_user_id = file.readAll()
  33.         -- Close the file
  34.         file.close()
  35.         local encryptedMessage = crypto.str_encrypt("aes-256-cbc", key, iv, "add user")
  36.         rednet.send(server_id, encryptedMessage)
  37.         local encrypted_admin_user_id = crypto.str_encrypt("aes-256-cbc", key, iv, admin_user_id)
  38.         rednet.send(server_id, encrypted_admin_user_id)
  39.         local _, response = rednet.receive()
  40.         local decryptedResponse = crypto.str_decrypt("aes-256-cbc", key, iv, response)
  41.         if (decryptedResponse == "user recognized") then
  42.             -- Send the user pass
  43.             local file = fs.open(mountPath .. "/user_pass.txt", "r")
  44.             -- Read the contents of the file
  45.             local admin_user_pass = file.readAll()
  46.             -- Close the file
  47.             file.close()
  48.             local encrypted_admin_user_pass = crypto.str_encrypt("aes-256-cbc", key, iv, admin_user_pass)
  49.             rednet.send(server_id, encrypted_admin_user_pass)
  50.             local _, response = rednet.receive()
  51.             local decryptedResponse = crypto.str_decrypt("aes-256-cbc", key, iv, response)
  52.             if (decryptedResponse == "user verified") then
  53.                 -- Receive the new user pass and write it to the file
  54.                 local _, encrypted_new_admin_user_pass = rednet.receive()
  55.                 local new_admin_user_pass = crypto.str_decrypt("aes-256-cbc", key, iv, encrypted_new_admin_user_pass)
  56.                 local mountPath = disk.getMountPath("left")
  57.                 local file = fs.open(mountPath .. "/user_pass.txt", "w")
  58.                 file.write(new_admin_user_pass)
  59.                 file.close()
  60.                 local _, response = rednet.receive()
  61.                 local decryptedResponse = crypto.str_decrypt("aes-256-cbc", key, iv, response)
  62.                 if (decryptedResponse == "access granted") then
  63.                     -- Prompt the user for a unique user id
  64.                     local client_user_id = read("Please enter a unique user name for this card: ")
  65.                     local encrypted_client_user_id = crypto.str_encrypt("aes-256-cbc", key, iv, client_user_id)
  66.                     rednet.send(server_id, encrypted_client_user_id)
  67.                     local _, response = rednet.receive()
  68.                     local decryptedResponse = crypto.str_decrypt("aes-256-cbc", key, iv, response)
  69.                     if (decryptedResponse == "user added") then
  70.                         local _, encrypted_client_user_pass = rednet.receive()
  71.                         local client_user_pass = crypto.str_decrypt("aes-256-cbc", key, iv, encrypted_client_user_pass)
  72.                         local file = fs.open(mountPath .. "/user_pass.txt", "w")
  73.                         file.write(client_user_pass)
  74.                         file.close()
  75.                         local client_user_level = read("Please enter the access level to assign to this card. 1 for guest, 2 for employee or 3 for Administrator: ")
  76.                         local encrypted_client_user_level = crypto.str_encrypt("aes-256-cbc", key, iv, client_user_level)
  77.                         rednet.send(server_id, encrypted_client_user_level)
  78.                         print("The new user card has been properly set up. Thank you and goodbye.")
  79.                         sleep(3)
  80.                     else
  81.                         -- Inform the user that the chosen user id already exists
  82.                         print("The user name entered for this card already exists")
  83.                         sleep(3)
  84.                     end
  85.                 else
  86.                     -- Inform the user that the card in the right slot is not an admin account
  87.                     print("The disk inserted into the right drive is not an administrator account")
  88.                     sleep(3)
  89.                 end
  90.             else
  91.                 print("The disk inserted into the right drive has a mismatched user password. Please contact a site administrator.")
  92.                 sleep(3)
  93.             end
  94.         else
  95.             print("The disk inserted into the right drive is not a recognized user")
  96.             sleep(3)
  97.         end
  98.     else
  99.         print("Please insert a properly formatted admin card into the right drive")
  100.         sleep(3)
  101.     end
  102.     -- Eject both disks
  103.     disk.eject("left")
  104.     disk.eject("right")
  105. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement