Advertisement
NekoLogi

bank_card_creator.lua

Oct 6th, 2022 (edited)
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.23 KB | Source Code | 0 0
  1. function main()
  2.     while true do
  3.         -- Check for inserted floppy.
  4.         term.setCursorPos(1,1)
  5.         term.clear()
  6.         print("Bitte Bankkarte in Laufwerk stecken.")
  7.         term.setCursorPos(1,3)
  8.         print("Für eine neue karte:")
  9.         term.setCursorPos(3,4)
  10.         print("1. Karte aus box holen.")
  11.         term.setCursorPos(3,5)
  12.         print("2. Karte in Laufwerk schieben.")
  13.         local event, side = os.pullEvent("disk")
  14.         redstone.setAnalogOutput("front", 15)
  15.         sleep(1)
  16.         redstone.setAnalogOutput("front", 0)
  17.         create_card()
  18.         disk.eject(drive_card)
  19.     end
  20. end
  21.  
  22. function login()
  23.     local username = ""
  24.     local id = ""
  25.     local password = ""
  26.     local pin = ""
  27.  
  28.     -- Request username.
  29.     term.setCursorPos(1,1)
  30.     term.clear()
  31.     print("Gebe deinen Namen ein: ")
  32.     username = io.read()
  33.     id = disk.getID(drive_card)
  34.  
  35.     -- Check if user exists in database.
  36.     if not fs.exists(database_path .. username .. "/" .. username .. ".txt") then
  37.         term.setCursorPos(1,1)
  38.         term.clear()
  39.         print("Gebe ein neues Passwort ein: ")
  40.         password = io.read()
  41.         term.setCursorPos(1,1)
  42.         term.clear()
  43.         print("Gebe ein neuen PIN ein: ")
  44.         pin = io.read()
  45.  
  46.     else
  47.         for i = 1, 3 do
  48.             term.setCursorPos(1,1)
  49.             term.clear()
  50.             print("Benutzer existiert bereits! | versuche: " .. i .. "/3")
  51.             term.setCursorPos(1,2)
  52.             print("Gebe dein passwort ein: ")
  53.             password = io.read()
  54.             -- Get database account data and compare passwords.
  55.             local file = fs.open(database_path .. username .. "/" .. username .. ".txt", "r")
  56.             local client_name = file.readLine()
  57.             local client_id = encryption.decrypt(file.readLine(), 4)
  58.             local client_pin = encryption.decrypt(file.readLine(), 4)
  59.             local client_password = encryption.decrypt(file.readLine(), 4)
  60.             file.close()
  61.             -- Später löschen!!!!
  62.             print(client_name)
  63.             print(client_id)
  64.             print(client_pin)
  65.             print(client_password)
  66.             io.read()
  67.             --________________________________________________
  68.             if password == client_password then
  69.                 return { username, id, pin, password }
  70.             end
  71.         end
  72.         return {nil, nil}
  73.     end
  74.     return { username, id, pin, password }
  75. end
  76.  
  77. function create_card()
  78.     local account = login()
  79.     if account[1] == nil then
  80.         return
  81.     end
  82.     -- Create new card.
  83.     disk.setLabel(drive_card, account[1])
  84.     local file = fs.open(card_name, "w")
  85.     file.writeLine(encryption.encrypt(account[4], 5))
  86.     file.close()
  87.     -- Save new card to database.
  88.     local file = fs.open(database_path .. account[1] .. "/" .. account[1] .. ".txt", "w")
  89.     file.writeLine(account[1])
  90.     file.writeLine(encryption.encrypt(account[2], 4))
  91.     file.writeLine(encryption.encrypt(account[3], 4))
  92.     file.writeLine(encryption.encrypt(account[4], 4))
  93.     file.close()
  94. end
  95.  
  96.  
  97.  
  98. os.loadAPI("encryption.lua")
  99. drive_card = "bottom"
  100. card_name = "disk2/bank.txt"
  101. database_path = "disk/users/"
  102. drive_database = "back"
  103.  
  104. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement