Laizerox / php-wowemu-auth

GNU General Public License v3.0
17 stars 12 forks source link

Failed to authenticate with the script using trinity core. #4

Open NukedBart opened 1 year ago

NukedBart commented 1 year ago

Here's my register function implementation:

/* Connect to your CMaNGOS database. */
$db = new mysqli($dbHost, $dbUser, $dbPassword, $dbName);

/* If the form has been submitted. */
if (isset($_POST['register'])) {
    $username = $_POST['username'];
    $password = $_POST['password'];
    $email = $_POST['email'];

    /* Grab the users IP address. */
    $ip = $_SERVER['REMOTE_ADDR'];

    /* Set the join date. */
    $joinDate = date('Y-m-d H:i:s');

    /* Set GM Level. */
    $gmLevel = '0';

    /* Set expansion pack - Wrath of the Lich King. */
    $expansion = '2';

    /* Create your v and s values. */
    $client = new UserClient($username);
    $salt = $client->generateSalt();
    $verifier = $client->generateVerifier($password);

    /* Insert the data into the CMaNGOS database. */
    try{
        mysqli_query($db, "INSERT INTO account (username, verifier, salt, reg_mail, email, joindate, last_ip, expansion) VALUES ('$username', 0x$verifier, 0x$salt, '$email', '$email', '$joinDate', '$ip', '$expansion')");
        mysqli_query($db, "INSERT INTO realmcharacters (realmid, acctid, numchars) SELECT realmlist.id, account.id, 0 FROM realmlist, account LEFT JOIN realmcharacters ON acctid = account.id WHERE acctid IS NULL");
    }
    catch(Exception $e){
        echo '';
    }
    /* Do some stuff to let the user know it was a successful or unsuccessful attempt. */
    echo "INSERT INTO account (username, verifier, salt, reg_mail, email, joindate, last_ip, expansion) VALUES ('$username', '0x$verifier', '0x$salt', '$email', '$email', '$joinDate', '$ip', '$expansion')";
}
Laizerox commented 1 year ago

This is interesting. I looked into g and N values which is usually the main culprit for issues, but they seem to be identical to cmangos.

I looked more deeply into this within 10 minutes and I believe cmangos handles salt and verifier in different way compared to TrinityCore.

I could point where to look for this and in order to make this work on both emulators. First thing first is we would need to figure out the identical set of salt and verifier for identical user and password to test for both.

@NukedBart is there someone in TrinityCore scene that could potentially help or contact me? I am very busy and swamped with work to make this work in my free time currently completely alone.

NukedBart commented 1 year ago

I'll post two queries in some hours, one generated from trinity core console and the other from the script.

Laizerox commented 1 year ago

I would also probably start with if cmangos default accounts work with TrinityCore and vice versa. If they do that would be great starting point for me.

What we need is ability to consistently reproduce the faulty logic so I can create UnitTests to test the values and fix based on that.

NukedBart commented 1 year ago

worldserver returned: 'TEST', 0x344bc8f696060ed6d54e53728ca71127d95f6b742cafc2ebc4e5fdc78b4e926c, 0x1e2a60088b81c55ea13f1eac89fadca6126411d42d003b18bf9ded12cddef02a with username test password test

script returned: 'test', 0x7a84912438e5961cc3873041753154350e5f077b6742dea6cb0154b72a086de8, 0x1cee109975d547af94102dda1706a3957cd7a5ae2d4e0ee0f1e1b0a2d68bbfff with username test password test :: the salt values are not identical.

script returned: 'test', 0x344bc8f696060ed6d54e53728ca71127d95f6b742cafc2ebc4e5fdc78b4e926c, 0x597a47e5c7ee5d5958661629412909366e94f29172248611faa809d2a6bcfc7f with username test password test :: the salt values are identical.

it could be possibly a case issue, excluded, both return the same

Laizerox commented 1 year ago

@NukedBart please remember that salt IS supposed to be different for each creation process / account. Its literally random bytes.

But I would suggest you to try to use cmangos default admin credentials in TrinityCore and then let me know if it works or not.

Laizerox commented 1 year ago

@NukedBart but thanks for verifier and salt generated by TrinityCore I can see if I can reproduce with that using my ts-wowemu-auth

NukedBart commented 1 year ago

@NukedBart please remember that salt IS supposed to be different for each creation process / account. Its literally random bytes.

But I would suggest you to try to use cmangos default admin credentials in TrinityCore and then let me know if it works or not.

my table was empty at creation

NukedBart commented 1 year ago

is there any updates