Advertisement
NekoLogi

bank.lua

Oct 6th, 2022
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.08 KB | Source Code | 0 0
  1. function main()
  2.     while true do
  3.         ::Start::
  4.         -- Check for inserted floppy.
  5.         term.setCursorPos(1,1)
  6.         term.clear()
  7.         monitor.clear()
  8.         print("Bitte Bankkarte in Laufwerk stecken.")
  9.         term.setCursorPos(1,3)
  10.         print("Für eine neue karte:")
  11.         term.setCursorPos(3,4)
  12.         print("1. Karte aus box holen.")
  13.         term.setCursorPos(3,5)
  14.         print("2. Karte in Laufwerk schieben.")
  15.         local event, side = os.pullEvent("disk")
  16.         if ~login() then
  17.             term.setCursorPos(1,1)
  18.             term.clear()
  19.             monitor.clear()
  20.             print("Bankkarte ungültig!")
  21.             drive.eject("front")
  22.             sleep(3)
  23.             goto Start
  24.         end
  25.  
  26.         -- Let user choose between (überweisen, karte erstellen).
  27.         term.setCursorPos(1,1)
  28.         term.clear()
  29.         monitor.clear()
  30.         term.setBackgroundColor(4096)
  31.         term.setCursorPos(1,1)
  32.         print("Überweisen")
  33.         term.setCursorPos(1,2)
  34.         print("Placeholder")
  35.         term.setBackgroundColor(32768)
  36.         while true do
  37.             local event, side, x, y = os.pullEvent()
  38.             if event == "monitor_touch" then
  39.                 if y == 1 then
  40.                 elseif y == 2 then
  41.                     break
  42.                 elseif y == 3 then
  43.                     break
  44.                 end
  45.             end
  46.         end
  47.         drive.eject("front")
  48.     end
  49. end
  50.  
  51. function login()
  52.     local name = ""
  53.     local id = ""
  54.     local password = ""
  55.  
  56.     -- Check who's disk it is.
  57.     name = drive.getLabel(drive_pos)
  58.  
  59.     -- Get unique id from disk.
  60.     id = drive.getID(drive_pos)
  61.  
  62.     -- Read bank card and decrypt password.
  63.     if ~fs.exists(card_name) then
  64.         return false
  65.     end
  66.     local file = fs.open(card_name, "r")
  67.     password = encryption.Decrypt(file.readLine(), 5)
  68.  
  69.     -- get 4 digit pin, password and username from database.
  70.     file = fs.open(database_path .. name .. ".txt")
  71.     local client_name = file.readLine()
  72.     local client_id = encryption.Decrypt(file.readLine(), 4)
  73.     local client_pin = encryption.Decrypt(file.readLine(), 4)
  74.     local client_password = encryption.Decrypt(file.readLine(), 4)
  75.  
  76.     -- compare password and username with database.
  77.     if password ~= client_password or name ~= client_name then
  78.         return false
  79.     end
  80.    
  81.     -- Request 4 digit pin from user.
  82.     for i = 1, 3 do
  83.         local pin = ""
  84.         local pin_char = ""
  85.         term.clear()
  86.         monitor.clear()
  87.         term.setCursorPos(1,1)
  88.         term.clearLine()
  89.         print("Gib deine PIN ein: " .. pin_char)
  90.         term.setBackgroundColor(4096)
  91.         term.setCursorPos(1,2)
  92.         print("789")
  93.         term.setCursorPos(1,3)
  94.         print("456")
  95.         term.setCursorPos(1,4)
  96.         print("123")
  97.         term.setCursorPos(2,5)
  98.         print("0")
  99.         term.setBackgroundColor(32768)
  100.         local event, side, x, y = os.pullEvent()
  101.         for i = 1, 4 do
  102.             if event == "monitor_touch" then
  103.                 if x == 2 and y == 5 then
  104.                     pin = pin + "0"
  105.                     pin_char = pin_char + "*"
  106.                 elseif x == 1 and y == 2 then
  107.                     pin = pin + "7"
  108.                     pin_char = pin_char + "*"
  109.                 elseif x == 2 and y == 2 then
  110.                     pin = pin + "8"
  111.                     pin_char = pin_char + "*"
  112.                 elseif x == 3 and y == 2 then
  113.                     pin = pin + "9"
  114.                     pin_char = pin_char + "*"
  115.  
  116.                 elseif x == 1 and y == 3 then
  117.                     pin = pin + "4"
  118.                     pin_char = pin_char + "*"
  119.                 elseif x == 2 and y == 3 then
  120.                     pin = pin + "5"
  121.                     pin_char = pin_char + "*"
  122.                 elseif x == 3 and y == 3 then
  123.                     pin = pin + "6"
  124.                     pin_char = pin_char + "*"
  125.  
  126.                 elseif x == 1 and y == 4 then
  127.                     pin = pin + "1"
  128.                     pin_char = pin_char + "*"
  129.                 elseif x == 2 and y == 4 then
  130.                     pin = pin + "2"
  131.                     pin_char = pin_char + "*"
  132.                 elseif x == 3 and y == 4 then
  133.                     pin = pin + "3"
  134.                     pin_char = pin_char + "*"
  135.                 end
  136.             end
  137.         end
  138.         if pin == client_pin then
  139.             term.clear()
  140.             monitor.clear()
  141.             print("Willkommen " .. name)
  142.             sleep(3)
  143.             return true
  144.         end
  145.     end
  146. end
  147.  
  148. function send()
  149.     -- Request amount and receiver.
  150.  
  151.     -- Send Money if available.
  152. end
  153.  
  154. -- Card data structure:
  155.     -- Password (Enc.5)
  156. -- Database data structure:
  157.     -- Username
  158.     -- ID (Enc.4)
  159.     -- PIN (Enc.4)
  160.     -- Password (Enc.4)
  161.     -- Cash
  162.  
  163. os.loadAPI("encryption.lua")
  164. monitor = peripheral.wrap("top")
  165. monitor.setTextScale(1)
  166. drive = peripheral.wrap("bottom")
  167. drive_pos = "right"
  168. card_name = "disk/bank.txt"
  169. database_path = "disk/users/"
  170. database = peripheral.wrap("back")
  171.  
  172. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement