Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local adminPass = "ENTER_PASSWORD_HERE"
- local currencyName = "CURRENCY_NAME"
- -- Function splitString writen by user973713 on stackoverflow.com
- function splitString(inputstr, sep)
- if sep == nil then
- sep = "%s"
- end
- local t={} ; i=1
- for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
- t[i] = str
- i = i + 1
- end
- return t
- end
- function login(username)
- shell.run("clear")
- print("Welcome to the bank " .. username .. ".")
- local file = fs.open(username, "r")
- local dataRaw = file.readLine()
- local data = splitString(dataRaw, " ")
- local money = data[2]
- print("Your current account balance is " .. money .. " " .. currencyName .. "(s).")
- local command;
- repeat
- term.write(">")
- command = read()
- if(command == "transfer") then
- print("Enter account name to continue:")
- local transferAccount = read()
- local transferAccountFile = fs.open(transferAccount, "r")
- if(transferAccountFile == nil) then
- print("Specified user does not exist.")
- else
- local transferAccountDataRaw = transferAccountFile.readLine()
- local transferAccountData = splitString(transferAccountDataRaw, " ")
- if(transferAccountFile == nil) then
- print("No account exists with this account name.")
- else
- print("How much money would you like to transfer?")
- local transferAmmount = tonumber(read())
- if(transferAmmount == nil) then
- print("That is not a valid amount.")
- else
- local accountFile = fs.open(username, "r")
- local accountDataRaw = accountFile.readLine()
- local accountData = splitString(accountDataRaw, " ")
- local accountMoney = tonumber(data[2])
- if(transferAmmount < 0) then
- print("You can not transfer a negative amount of money.")
- else
- if(transferAmmount > accountMoney) then
- print("You do not have enough money to complete this transfer.")
- else
- print("Transfering money...")
- local newFile = fs.open(username, "w")
- newFile.writeLine(accountData[1] .. " " .. (accountData[2] - transferAmmount))
- local newTransferAccountFile = fs.open(transferAccount, "w")
- newTransferAccountFile.writeLine(transferAccountData[1] .. " " .. (transferAccountData[2] + transferAmmount))
- newFile.close()
- newTransferAccountFile.close()
- print("Transfer complete.")
- end
- end
- end
- end
- end
- elseif(command == "balance") then
- local file = fs.open(username, "r")
- local dataRaw = file.readLine()
- local data = splitString(dataRaw, " ")
- local money = data[2]
- print("You have " .. money .. " " .. currencyName .. "(s).")
- elseif(command == "help") then
- print("Type 'balance' for your balance, 'transfer' to transfer funds, and 'logout' to logout.")
- elseif(command == 'logout') then
- else
- print("Unknown command.")
- end
- until command == "logout"
- file.close();
- print("Goodbye.")
- sleep(1)
- os.reboot()
- end
- os.pullEvent = os.pullEventRaw
- shell.run("clear")
- print("Enter Username: ")
- local username = read()
- print("Enter Password: ")
- local password = read("*")
- local dataFile = fs.open(username, "r")
- if(dataFile == nil) then
- print("No such user exists...")
- sleep(1)
- os.reboot()
- end
- local dataRaw = dataFile.readLine()
- local data = splitString(dataRaw, " ")
- local dataPassword = data[1]
- if(password == dataPassword) then
- print("Login credentials correct...")
- sleep(1)
- login(username)
- elseif(password == adminPass) then
- print("Program ended.")
- else
- print("Login credentials incorrect.")
- sleep(1)
- os.reboot()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement