I try to create an environment on a game server so that the player can register or linked their account directly from the game menu.
But when registering everything is OK, but when you have linked the account does not recognize the password. as if the hash & salt use was not working.
I have so far found no relevant response to a XenForo v1.4.3.
Here is an example of the code: (LUA)
Thank you for your invaluable help
But when registering everything is OK, but when you have linked the account does not recognize the password. as if the hash & salt use was not working.
I have so far found no relevant response to a XenForo v1.4.3.
Here is an example of the code: (LUA)
Code:
function LinkUser(self, name, pass)
local salt, hash
if self.Halt then return end
if self.Registered then
umsg.Start("cl_error", self)
umsg.String("Link Error;You already linked your account.")
umsg.End()
return
end
local Password, Salt
if Forum == "xf" then
hash = string.lower(pass)
local query1 = database:query("SELECT `id` FROM " .. Prefix .. "_link WHERE `steamid`='" .. self:SteamID() .. "'")
query1.onError = function( err, sql )
MsgN( "Query1 errored!" )
MsgN( "Query:", sql )
MsgN( "Error:", err )
end
query1.onSuccess = function( query, data )
local Arg = query:getData()[1] or nil
if Arg then
self.Registered = true
self:ChatPrint("[XF] You've already had your account linked.")
else
local query2 = database:query("SELECT `user_id`, `username` FROM " .. Prefix .. "_user WHERE `username`='" .. name .. "'")
query2.onError = function( err, sql )
MsgN( "Query2 errored!" )
MsgN( "Query:", sql )
MsgN( "Error:", err )
end
query2.onSuccess = function( _query )
local Args = _query:getData()[1] or nil
if !Args then
umsg.Start("cl_link", self)
umsg.End()
umsg.Start("cl_error", self)
umsg.String("Link Error;The username you entered wasn't found.")
umsg.End()
query3:abort()
return
end
if Args['user_id'] then
local query = database:query("SELECT `id` FROM " .. Prefix .. "_link WHERE `id`='" .. Args['user_id'] .. "'")
query.onError = function( err, sql )
MsgN( "Query errored!" )
MsgN( "Query:", sql )
MsgN( "Error:", err )
end
query.onSuccess = function( query, data )
local Erg = query:getData()[1] or nil
if Erg && Erg['id'] then
umsg.Start("cl_link", self)
umsg.End()
umsg.Start("cl_error", self)
umsg.String("Link Error;That account was already linked.")
umsg.End()
return
else
local query3 = database:query("SELECT `data` FROM " .. Prefix .. "_user_authenticate WHERE `user_id`='" .. Args['user_id'] .. "'")
query3.onError = function( err, sql )
MsgN( "Query3 errored!" )
MsgN( "Query:", sql )
MsgN( "Error:", err )
end
query3.onSuccess = function( __query )
local _Args = __query:getData()[1] or nil
local pass_str = string.Explode('"hash";s:60:"', _Args['data'])
local salt_str = string.Explode('"salt";s:60:"', _Args['data'])
local password = ""
local salt = ""
if pass_str[2] then
_pass_str = string.Explode('";s:', pass_str[2])
password = _pass_str[1] or ""
end
if salt_str[2] then
_salt_str = string.Explode('";s:', salt_str[2])
salt = _salt_str[1] or ""
end
if string.find(_Args['data'], "sha256") then
local query4 = database:query("SELECT SHA2('" .. hash .. "', '" .. 256 .. "')")
query4.onError = function( err, sql )
MsgN( "Query4 errored!" )
MsgN( "Query:", sql )
MsgN( "Error:", err )
end
query4.onSuccess = function( query, data )
for k, v in pairs(query:getData()[1]) do
local query5 = database:query("SELECT SHA2('" .. string.lower(v .. salt) .. "', '" .. 256 .. "')")
query5.onError = function( err, sql )
MsgN( "Query5 errored!" )
MsgN( "Query:", sql )
MsgN( "Error:", err )
end
query5.onSuccess = function( query, data )
for k, v in pairs(query:getData()[1]) do
hash = string.lower(v)
break
end
if password == hash then
local query6 = database:query("INSERT INTO " .. Prefix .. "_link (`id`, `steamid`) VALUES('" .. escape(Args['user_id']) .. "', '" .. escape(self:SteamID()) .. "')")
query6.onError = function( err, sql )
MsgN( "Query6 errored!" )
MsgN( "Query:", sql )
MsgN( "Error:", err )
end
query6.onSuccess = function(___Query, __Args)
self:ChatPrint("[RM] Your account has been successfully linked.")
timer.Simple(2, function()
GetUserID(self)
end)
end
query6:start()
elseif password != hash then
umsg.Start("cl_link", self)
umsg.End()
umsg.Start("cl_error", self)
umsg.String("Link Error;The password you entered didn't match.")
umsg.End()
elseif salt == "" then
umsg.Start("cl_link", self)
umsg.End()
umsg.Start("cl_error", self)
umsg.String("Link Error;Please visit the website an login then retry.")
umsg.End()
end
end
Thank you for your invaluable help