Guest User

Untitled

a guest
Aug 12th, 2018
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. function login()
  2. while true do
  3.  
  4. print("Welcome, press 1 to login, or press 2 to sign up.")
  5. local choice
  6. choice = io.read()
  7.  
  8. if tonumber(choice) == 1 then
  9.  
  10. user_list = {}
  11. check_table = {}
  12. file = io.open("user_saves/test.txt")
  13. while true do
  14. local pair = file:read()
  15. if pair == nil then
  16. break
  17. else
  18. username, password = pair:match("([^,]+),([^,]+)")
  19. user_list[username] = password
  20. check_table[username] = true
  21. end
  22. end
  23.  
  24. print("Welcome! Please Enter Username: ")
  25. local username
  26. username = io.read()
  27.  
  28. if check_table[username] then
  29. local password
  30. print("Password: ")
  31. password = io.read()
  32.  
  33. if user_list[username] == password then
  34.  
  35. local cash
  36. print("Withdraw: ")
  37. cash = io.read()
  38. Account:withdraw(cash)
  39.  
  40. break
  41. else
  42. print("Password incorrect, try again...")
  43. end
  44.  
  45. else
  46. print("Invalid username, try again...")
  47. end
  48.  
  49. elseif tonumber(choice) == 2 then
  50.  
  51. print("Enter Username: ")
  52. local username
  53. username = io.read()
  54.  
  55. print("Enter Password: ")
  56. local password
  57. password = io.read()
  58.  
  59. file = io.open("user_saves/test.txt", "a")
  60. file:write(username .. "," .. password, "\n")
  61. file:flush()
  62.  
  63. Account:create(username)
  64.  
  65. else
  66. print("Invalid choice entered, try again...")
  67.  
  68. end
  69. end
  70. end
  71.  
  72. Account = {}
  73. Account.__index = Account
  74.  
  75. function Account:create(user)
  76. local acc = {}
  77. setmetatable(acc,Account)
  78. acc.balance = 1000
  79. acc.user = user
  80. end
  81.  
  82. function Account:withdraw(amount)
  83. self.balance = self.balance - amount
  84. print("current balance: " .. acc.balance)
  85. end
  86.  
  87. login()
Add Comment
Please, Sign In to add comment