Decode Hash not Ok

jeje031

Member
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)

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 :)
 

silence

Well-known member
You could try writing a php class that you can do requests to do generate the hashes for you.
 

jeje031

Member
problem lua does not accept all the php functions. suddenly I can only just going to do the maneuver via sql

:/
 

silence

Well-known member
problem lua does not accept all the php functions. suddenly I can only just going to do the maneuver via sql

:/
No what I mean is with LUA do a request to a file you create on xenforo like 'https://website.com/generate-password.php' and have something like this:

Code:
$startTime = microtime(true);
$fileDir = dirname(__FILE__);

require($fileDir . '/library/XenForo/Autoloader.php');
XenForo_Autoloader::getInstance()->setupAutoloader($fileDir . '/library');

XenForo_Application::initialize($fileDir . '/library', $fileDir);
XenForo_Application::set('page_start_time', $startTime);

$deps = new XenForo_Dependencies_Public();
$deps->preLoadData();

$response = new Zend_Controller_Response_Http();
$request = new Zend_Controller_Request_Http();

$input = new XenForo_Input($request);

$filteredInput = $input->filter(array(
    'apiKey' => XenForo_Input::STRING,
    'username' => XenForo_Input::STRING,
    'password' => XenForo_Input::STRING
));

$apiKeys = array(
    'FDSA978DFAS987FADS9078FDS98707F89D0A8970AFDS'
);

try
{
    if (!$request->isPost()) {
        $response->setHttpResponseCode(500);
        $logMessage = array('error' => 'post_request_only');
    }
    else if (!in_array($filteredInput['apiKey'], $this->apiKeys))
    {
        $response->setHttpResponseCode(500);
        $logMessage = array('error' => 'api_key_invalid');
    }
    else
    {
        // generate the hash here.
    }
}
catch (Exception $e)
{
    $response->setHttpResponseCode(500);
    XenForo_Error::logException($e);

    $logMessage = array('error' => 'fatal_error');
}

$response->setBody(json_encode($logMessage));
$response->sendResponse();
Then do a POST to this file with LUA and you can generate everything the way XenForo does it (you would have to dig through it's code to figure that out but should be easy!)
 
Top