QUERY not passing
# support-forum
w
bcrypt_verify(playerid, "OnPlayerLogin", inputtext, field);
is loading the correct data, the hash is printing the correct hash on the console but for some reason it's ignoring the arugment on
OnPlayerLogin
public OnPlayerLogin(playerid, bool:success)
and seem's to be ignoring the
if(success)
and going straight to the
else
does anyone have any thoughts on why it would do this? https://pastebin.com/7jeJKJJa
@refined-agent-73926 posted here with it being to big for the chat
r
How are you hashing your password?
w
bcrypt_hash(playerid, "OnPlayerRegister", inputtext, 12);
r
Can you post the hash value from your database? If possible..or show me how you inserting the hash into database
success value will only get false if invalid hash is passed (which should be reported in the logs) or hash wasn't able to validate the text
w
Copy code
forward OnPlayerRegister(playerid);
public OnPlayerRegister(playerid)
{
    new password[64];
    bcrypt_get_hash(password);

    new query[256];
    format(query, sizeof(query), "INSERT INTO `USERS` (`NAME`, `PASS`, `SCORE`, `KILLS`, `DEATHS`) VALUES ('%q', '%s', '%d', '%d', '%d')", ReturnName(playerid), password, GetPlayerScore(playerid), Character[playerid][pKills], Character[playerid][pDeaths]);
    database_result = db_query(server_database, query);
    db_free_result(database_result);

    Character[playerid][pLoggedIn] = true;
    
    SendServerMessage(playerid, "SERVER: You have successfully registered an account.");
    printf(query);;
    return 1;
}
``$2a$12$Ywy58I1o0I/sq0AzXO7rMe0IhapDMbtWFjzNLjIFGH4OoDtMKH/d``
r
Is there any errors reported by plugin in logs?
yeah that hash is invalid
w
none at all, according to the log everything is being updated as intended
Copy code
[02:05:42] SELECT `PASS` FROM `USERS` WHERE `NAME` = 'TEST' COLLATE NOCASE
[02:05:42] $2y$12$g41LTNRN/F3hChpt6ziVWeVUvsvzvhfza6cKe8hEs0H09hXA/gvwW
r
The hash you posted above is not valid
Since you have posted two hashes.. is
NAME
attribute unique in your db?
w
No, its AI by ID and the second hash was because i deleted the DB for a fresh copy I'm really baffled as to why this has stopped working, the only major change i've made was easy dialog
r
Can you check if there's multiple entries for that particular name
w
It's a barren DB, i've just regened it this morning I've just checked the hash again for this one` $2y$12$ddNccjNUmvMNMTsRisi6gu88zP6toWy8Wb37ZnOLzSFN4YB45/xbq` its not hashing correctly for some reason
r
That's a valid hash
w
It just typed luke55 for this one, using a Bcrypt Hash Verifier and it says the plain text does not match the hash
r
Can you show the surrounding code?
w
Copy code
Dialog:REGISTER(playerid, response, listitem, inputtext[])
{
    if (response)
    {
         if(strlen(inputtext) < 6 || strlen(inputtext) > 24)
         {
            SendErrorMessage(playerid, "Your password must be from 6-8 Characters");
            return ShowPlayerDialog(playerid, REGISTER_DIALOG, DIALOG_STYLE_PASSWORD, "{FFFFFF}Register Account", "{FFFFFF}Please enter a password below to register an account:", "Enter", "Leave");
         }

         bcrypt_hash(playerid, "OnPlayerRegister", inputtext, 12);
         return 1;
    }
    else
    {
        Kick(playerid);
    }
    return 1;
}
Copy code
forward OnPlayerRegister(playerid);
public OnPlayerRegister(playerid)
{
    new password[64];
    bcrypt_get_hash(password);

    new query[256];
    format(query, sizeof(query), "INSERT INTO `USERS` (`NAME`, `PASS`, `SCORE`, `KILLS`, `DEATHS`) VALUES ('%q', '%s', '%d', '%d', '%d')", ReturnName(playerid), password, GetPlayerScore(playerid), Character[playerid][pKills], Character[playerid][pDeaths]);
    database_result = db_query(server_database, query);
    db_free_result(database_result);

    Character[playerid][pLoggedIn] = true;
    
    SendServerMessage(playerid, "SERVER: You have successfully registered an account.");
    printf(query);;
    return 1;
}
r
Let me try reproduce this code, this is easy dialog?
w
yaaa
Copy code
"pawn-lang/samp-stdlib",
        "https://github.com/Sreyas-Sreelal/samp-bcrypt:0.3.4",
        "Y-Less/sscanf:v2.13.2",
        "Skeatza/I-ZCMD:final",
        "Awsomedude/easyDialog:2.0",
        "oscar-broman/sqlitei"
full list of current dependencies im using to
I just tested it without easy dialog and it works completely fine its easydialog for some reason -_-
r
i haven't done any samp related stuff in past 7 years, but is this how easy dialog supposed to be used?
you're still using
Copy code
ShowPlayerDialog(playerid, REGISTER_DIALOG, DIALOG_STYLE_PASSWORD, "{FFFFFF}Register Account", "{FFFFFF}Please enter a password below to register an account:", "Enter", "Leave");
that's why I asked and i have done a simple code to check in easydialog it is working fine for me
w
omfg
was supposed to be Dialog_Show(playerid, REGISTER, DIALOG_STYLE_PASSWORD, "{FFFFFF}Register Account", "{FFFFFF}Please enter a password below to register an account:", "Enter", "Leave");
r
yes
w
Ok, that stupid mistake aside, it's still not working for me, i don't know if its not hashing correctly when registering a new account or if its not reading the hash correctly when logging in but I've just reverted back the samp natives for the dialog and it worked perfectly which means there's nothing wrong other then how its moving through the dialogs, the issue is either here
bcrypt_hash(playerid, "OnPlayerRegister", inputtext, 12);
or here
bcrypt_verify(playerid, "OnPlayerLogin", inputtext, field);
I think I might just have to find an alternative library what did you use in your test?
r
Copy code
C
#include <a_samp>
#include<easydialog>
#include<izcmd>
#include "../include/samp_bcrypt.inc"

CMD:test(playerid,params[]){
    Dialog_Show(playerid, REGISTER, DIALOG_STYLE_PASSWORD,"{FFFFFF}Register Account", "{FFFFFF}Please enter a password below to register an account:", "Enter", "Leave");    
    return 1;
}

Dialog:REGISTER(playerid, response, listitem, inputtext[]){
    if (response){
        bcrypt_hash(playerid, "OnPlayerRegister", inputtext, 12);
        return 1;
    }
    return 1;
}

forward OnPlayerRegister(playerid);
public OnPlayerRegister(playerid){
    new hash[64];
    bcrypt_get_hash(hash);
    bcrypt_verify(playerid, "verify", "test", hash);
    return 1;
}

forward verify(playerid,bool:success);
public verify(playerid,bool:success){    
    print(success ? "Yes" : "No");
    return 1;
}

main() {
    
}
w
sent you a pm with the base im using so you can see
all fixed and handled, thanks ❤️
r
np
w
use MD5 to hash passwords if you can
r
No don't do that and don't advise people to use md5 for hashing passwords
w
why not?
r
md5 has been broken for a very long time and also it was not meant to hash password, since it is a fast hashing algorithm. You should hash your passwords with slow algorithms like bcrypt