Advertisement
Guest User

Untitled

a guest
Mar 17th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.58 KB | None | 0 0
  1. local dbName = "";
  2. local dbHost = "";
  3. local dbUser = "";
  4. local dbPass = "";
  5. local dbPort = 0;
  6.  
  7. local database_connection = dbConnect("mysql", "dbname="..dbName..";host="..dbHost..";port="..dbPort..";charset=utf8", dbUser, dbPass, "autoreconnect=1")
  8.  
  9.  
  10.  
  11. function loginPlayer(username, password)
  12.     if username and password then
  13.         dbQuery(function(qh, player)
  14.             local result, rows_count = dbPoll(qh, 0)
  15.  
  16.             if rows_count == 1 then
  17.            
  18.                 passwordVerify(result[1]["members_pass_hash"], password, {}, function(result)
  19.                     if result == true then
  20.                         local account = getAccount(username)
  21.                        
  22.                         if not account then
  23.                             if not addAccount(username, password) then
  24.                                 outputChatBox("Unknown error at first login.", player)
  25.                             end
  26.                         else
  27.                             if getAccountPlayer(account) then
  28.                                 outputChatBox("This account is currently in use.", player)
  29.                                 return
  30.                             end
  31.                             setAccountPassword(account, password)
  32.                         end
  33.                            
  34.                         logIn(player, account, password)
  35.                         triggerClientEvent(player, "onClientPlayerLogin", player)
  36.                         outputChatBox("You have successfuly logged in.", player)
  37.                    
  38.                     else
  39.                         outputChatBox("Incorrect password.", player)
  40.                     end
  41.                 end)
  42.            
  43.             else
  44.                 outputChatBox("Account not found in database.", player)
  45.             end
  46.         dbFree(qh) end, database_connection, {client}, "SELECT members_pass_hash FROM accounts WHERE username=?") -- TODO: replace 'accounts' to database table name | replace 'username' to row name where username is
  47.     end
  48. end
  49. addEvent("login", true)
  50. addEventHandler("login", root, loginPlayer)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement