Advertisement
Link712011

Mail - server

Apr 20th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.73 KB | None | 0 0
  1. function user_exists(name)
  2.     local f = io.open("users/" .. name, "r")
  3.    
  4.     if f then
  5.         f:close()
  6.         return true
  7.     else
  8.         return false
  9.     end
  10. end
  11.  
  12. function create_account(name, passwd)
  13.     local file
  14.    
  15.     if not user_exists(name) then
  16.         file = io.open("users/" .. name, "w")
  17.         file:write(passwd)
  18.         file:close()
  19.         return true
  20.     end
  21.     return false
  22. end
  23.  
  24. function verify_account(name, passwd)
  25.     local f, str
  26.    
  27.     if user_exists(name) then
  28.         f = io.open("users/" .. name, "r")
  29.         str = f:read("*a")
  30.         f:close()
  31.         if str == passwd then
  32.             return true
  33.         end
  34.     end
  35.     return false
  36. end
  37.  
  38. create_account("chesno_a", "zizi")
  39. create_account("tangeek", "mdp")
  40. print(verify_account("tangeek", "mdp"))
  41. print(verify_account("tangeek", "mdpaa"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement