Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function main()
- while true do
- -- Check for inserted floppy.
- term.setCursorPos(1,1)
- term.clear()
- print("Bitte Bankkarte in Laufwerk stecken.")
- term.setCursorPos(1,3)
- print("Für eine neue karte:")
- term.setCursorPos(3,4)
- print("1. Karte aus box holen.")
- term.setCursorPos(3,5)
- print("2. Karte in Laufwerk schieben.")
- local event, side = os.pullEvent("disk")
- redstone.setAnalogOutput("front", 15)
- sleep(1)
- redstone.setAnalogOutput("front", 0)
- create_card()
- disk.eject(drive_card)
- end
- end
- function login()
- local username = ""
- local id = ""
- local password = ""
- local pin = ""
- -- Request username.
- term.setCursorPos(1,1)
- term.clear()
- print("Gebe deinen Namen ein: ")
- username = io.read()
- id = disk.getID(drive_card)
- -- Check if user exists in database.
- if not fs.exists(database_path .. username .. "/" .. username .. ".txt") then
- term.setCursorPos(1,1)
- term.clear()
- print("Gebe ein neues Passwort ein: ")
- password = io.read()
- term.setCursorPos(1,1)
- term.clear()
- print("Gebe ein neuen PIN ein: ")
- pin = io.read()
- else
- for i = 1, 3 do
- term.setCursorPos(1,1)
- term.clear()
- print("Benutzer existiert bereits! | versuche: " .. i .. "/3")
- term.setCursorPos(1,2)
- print("Gebe dein passwort ein: ")
- password = io.read()
- -- Get database account data and compare passwords.
- local file = fs.open(database_path .. username .. "/" .. username .. ".txt", "r")
- local client_name = file.readLine()
- local client_id = encryption.decrypt(file.readLine(), 4)
- local client_pin = encryption.decrypt(file.readLine(), 4)
- local client_password = encryption.decrypt(file.readLine(), 4)
- file.close()
- -- Später löschen!!!!
- print(client_name)
- print(client_id)
- print(client_pin)
- print(client_password)
- io.read()
- --________________________________________________
- if password == client_password then
- return { username, id, pin, password }
- end
- end
- return {nil, nil}
- end
- return { username, id, pin, password }
- end
- function create_card()
- local account = login()
- if account[1] == nil then
- return
- end
- -- Create new card.
- disk.setLabel(drive_card, account[1])
- local file = fs.open(card_name, "w")
- file.writeLine(encryption.encrypt(account[4], 5))
- file.close()
- -- Save new card to database.
- local file = fs.open(database_path .. account[1] .. "/" .. account[1] .. ".txt", "w")
- file.writeLine(account[1])
- file.writeLine(encryption.encrypt(account[2], 4))
- file.writeLine(encryption.encrypt(account[3], 4))
- file.writeLine(encryption.encrypt(account[4], 4))
- file.close()
- end
- os.loadAPI("encryption.lua")
- drive_card = "bottom"
- card_name = "disk2/bank.txt"
- database_path = "disk/users/"
- drive_database = "back"
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement