Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function login()
- while true do
- print("Welcome, press 1 to login, or press 2 to sign up.")
- local choice
- choice = io.read()
- if tonumber(choice) == 1 then
- user_list = {}
- check_table = {}
- file = io.open("user_saves/test.txt")
- while true do
- local pair = file:read()
- if pair == nil then
- break
- else
- username, password = pair:match("([^,]+),([^,]+)")
- user_list[username] = password
- check_table[username] = true
- end
- end
- print("Welcome! Please Enter Username: ")
- local username
- username = io.read()
- if check_table[username] then
- local password
- print("Password: ")
- password = io.read()
- if user_list[username] == password then
- local cash
- print("Withdraw: ")
- cash = io.read()
- Account:withdraw(cash)
- break
- else
- print("Password incorrect, try again...")
- end
- else
- print("Invalid username, try again...")
- end
- elseif tonumber(choice) == 2 then
- print("Enter Username: ")
- local username
- username = io.read()
- print("Enter Password: ")
- local password
- password = io.read()
- file = io.open("user_saves/test.txt", "a")
- file:write(username .. "," .. password, "\n")
- file:flush()
- Account:create(username)
- else
- print("Invalid choice entered, try again...")
- end
- end
- end
- Account = {}
- Account.__index = Account
- function Account:create(user)
- local acc = {}
- setmetatable(acc,Account)
- acc.balance = 1000
- acc.user = user
- end
- function Account:withdraw(amount)
- self.balance = self.balance - amount
- print("current balance: " .. acc.balance)
- end
- login()
Add Comment
Please, Sign In to add comment