Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local dbName = "";
- local dbHost = "";
- local dbUser = "";
- local dbPass = "";
- local dbPort = 0;
- local database_connection = dbConnect("mysql", "dbname="..dbName..";host="..dbHost..";port="..dbPort..";charset=utf8", dbUser, dbPass, "autoreconnect=1")
- function loginPlayer(username, password)
- if username and password then
- dbQuery(function(qh, player)
- local result, rows_count = dbPoll(qh, 0)
- if rows_count == 1 then
- passwordVerify(result[1]["members_pass_hash"], password, {}, function(result)
- if result == true then
- local account = getAccount(username)
- if not account then
- if not addAccount(username, password) then
- outputChatBox("Unknown error at first login.", player)
- end
- else
- if getAccountPlayer(account) then
- outputChatBox("This account is currently in use.", player)
- return
- end
- setAccountPassword(account, password)
- end
- logIn(player, account, password)
- triggerClientEvent(player, "onClientPlayerLogin", player)
- outputChatBox("You have successfuly logged in.", player)
- else
- outputChatBox("Incorrect password.", player)
- end
- end)
- else
- outputChatBox("Account not found in database.", player)
- end
- 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
- end
- end
- addEvent("login", true)
- addEventHandler("login", root, loginPlayer)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement