Burgershot
  • Home
  • Members
  • Team
  • Help
  • Search
  • Register
  • Login
  • Home
  • Members
  • Help
  • Search
Burgershot SA-MP Pawn Scripting [Pawn] bcrypt

 
  • 0 Vote(s) - 0 Average
Pawn bcrypt
Behemoth
Offline

Burgershot Member
Posts: 25
Threads: 4
Joined: Jan 2021
Reputation: 1
Location: Northern Ireland, UK
#1
2021-01-30, 05:43 PM
Hey

I'm moving from whirlpool to bcrypt and really can't understand it. can someone give me an example of how you'd verify a password is the same as what is held in the sql db? i can register fine and it saves the password correctly, i'm just struggling to actually check it.

thanks
Manyula
Offline

Burgershot Member
Posts: 52
Threads: 5
Joined: Apr 2019
Reputation: 5
Location: Germany
#2
2021-01-30, 07:19 PM
The whole point of a hashing algorithm is to take an input, manipulate the data and output a unique representation of the original input (=hash) that cannot be reverted to its original input. If a user now inputs a password, you need to hash it and compare the hash of the user's input against the hash persisted in your database. If both hashes are equal the user has entered the correct password.

If you're looking into hashing passwords or any kind of sensitive data, you might also want to look into salting.


Hope this helps!
Behemoth
Offline

Burgershot Member
Posts: 25
Threads: 4
Joined: Jan 2021
Reputation: 1
Location: Northern Ireland, UK
#3
2021-01-30, 08:04 PM
(2021-01-30, 07:19 PM)Manyula Wrote: The whole point of a hashing algorithm is to take an input, manipulate the data and output a unique representation of the original input (=hash) that cannot be reverted to its original input. If a user now inputs a password, you need to hash it and compare the hash of the user's input against the hash persisted in your database. If both hashes are equal the user has entered the correct password.

If you're looking into hashing passwords or any kind of sensitive data, you might also want to look into salting.


Hope this helps!

Yeah, I've been doing that but I'm getting this in the console
Quote:[SampBcrypt] [error]: LoginVerification => InvalidHash("")
Manyula
Offline

Burgershot Member
Posts: 52
Threads: 5
Joined: Apr 2019
Reputation: 5
Location: Germany
#4
2021-01-30, 10:53 PM
I haven't really done anything with the bcrypt plugin, so for me that error is nothing to really go on. Mind sharing your code?
Awide
Offline

Burgershot Member
Posts: 62
Threads: 5
Joined: Sep 2019
Reputation: 5
#5
2021-01-31, 05:25 PM
Post your code!
Behemoth
Offline

Burgershot Member
Posts: 25
Threads: 4
Joined: Jan 2021
Reputation: 1
Location: Northern Ireland, UK
#6
2021-02-01, 08:30 PM
Code:
            mysql_format(dbConnection, query, sizeof(query), "SELECT acc_pass FROM accounts WHERE acc_user = '%e'", ReturnName(playerid));
            mysql_tquery(dbConnection, query);

            cache_get_value_name(0, "acc_pass", password, 256);

            bcrypt_hash(0, "LoginVerification", password, 12);

Code:
forward LoginVerification(playerid);
public LoginVerification(playerid) {
    new
        hash[256], check[256];

    bcrypt_get_hash(hash);

    bcrypt_verify(playerid, "HashCheck", hash, check);
    return 1;
}

forward HashCheck(playerid, bool:success);
public HashCheck(playerid, bool:success) {
    if(success) {
        return SendClientMessage(playerid, COLOR_LIGHTRED, "IT WORKS CUNT");
    }
    return 1;

I have a feeling this is entirely wrong but I was just guessing at this point, was hoping for a guide on how to properly use this. nohate lol
Jarnokai
Offline

Burgershot Member
Posts: 53
Threads: 5
Joined: Apr 2019
Reputation: 0
Location: Oulu, Finland
#7
2021-02-02, 04:09 PM
(2021-02-01, 08:30 PM)Behemoth Wrote:
Code:
mysql_format(dbConnection, query, sizeof(query), "SELECT acc_pass FROM accounts WHERE acc_user = '%e'", ReturnName(playerid));
mysql_tquery(dbConnection, query);

cache_get_value_name(0, "acc_pass", password, 256);

bcrypt_hash(0, "LoginVerification", password, 12);

Code:
forward LoginVerification(playerid);
public LoginVerification(playerid) {
new
hash[256], check[256];

bcrypt_get_hash(hash);

bcrypt_verify(playerid, "HashCheck", hash, check);
return 1;
}

forward HashCheck(playerid, bool:success);
public HashCheck(playerid, bool:success) {
if(success) {
return SendClientMessage(playerid, COLOR_LIGHTRED, "IT WORKS CUNT");
}
return 1;

I have a feeling this is entirely wrong but I was just guessing at this point, was hoping for a guide on how to properly use this. nohate lol

I believe you do not need to pass the hashed version of the password into bcrypt_verify, instead you pass the stored hash and the plaintext input.
So when logging in, you can skip the entire process with "LoginVerification" and just instantly jump to bcrypt_verify with HashCheck.
Jarnokai
Offline

Burgershot Member
Posts: 53
Threads: 5
Joined: Apr 2019
Reputation: 0
Location: Oulu, Finland
#8
2021-02-02, 04:11 PM
See attached code from my gamemode:

Code:
if (strlen(pBcrypt[playerid]))
{
bcrypt_verify(playerid,"OnPasswordVerify",inputtext,pBcrypt[playerid]);
}


pBcrypt is where I store the hash that has been loaded from the player files. Under OnPasswordVerify I set the player as logged in if success == true.
Behemoth
Offline

Burgershot Member
Posts: 25
Threads: 4
Joined: Jan 2021
Reputation: 1
Location: Northern Ireland, UK
#9
2021-02-02, 11:41 PM
(2021-02-02, 04:11 PM)Jarnokai Wrote: See attached code from my gamemode:

Code:
if (strlen(pBcrypt[playerid]))
{
bcrypt_verify(playerid,"OnPasswordVerify",inputtext,pBcrypt[playerid]);
}


pBcrypt is where I store the hash that has been loaded from the player files. Under OnPasswordVerify I set the player as logged in if success == true.

I've tried doing so, unfortunately still getting "[SampBcrypt] [error]: LoginVerification => InvalidHash("")"
Jarnokai
Offline

Burgershot Member
Posts: 53
Threads: 5
Joined: Apr 2019
Reputation: 0
Location: Oulu, Finland
#10
2021-02-03, 09:39 AM
(2021-02-02, 11:41 PM)Behemoth Wrote: I've tried doing so, unfortunately still getting "[SampBcrypt] [error]: LoginVerification => InvalidHash("")"


(2021-02-02, 04:09 PM)Jarnokai Wrote: when logging in, you can skip the entire process with "LoginVerification" and just instantly jump to bcrypt_verify with HashCheck.
ImOver
Offline

Burgershot Member
Posts: 10
Threads: 0
Joined: Feb 2021
Reputation: 2
#11
2021-02-16, 07:13 PM (This post was last modified: 2021-02-16, 07:15 PM by ImOver.)
Of course it is invalid.


(2021-01-30, 07:19 PM)Manyula Wrote: The whole point of a hashing algorithm is to take an input, manipulate the data and output a unique representation of the original input (=hash) that cannot be reverted to its original input. If a user now inputs a password, you need to hash it and compare the hash of the user's input against the hash persisted in your database. If both hashes are equal the user has entered the correct password.

If you're looking into hashing passwords or any kind of sensitive data, you might also want to look into salting.


Hope this helps!

That is actually not how bcrypt works, unlike SHA256 and MD5 where you have to hash the actual input so that you can compare passwords.

I'll be explaining how to hash/check passwords

When you show the register dialog for a player. You check if the input is long/short etc. Then you use bcrypt_hash function and pass the playerid argument then you do create a variabe where you will store the hash using bcrpt_get_hash function (Call the variable whatever you want and make sure the variable's size is "BCRYPT_HASH_LENGTH") then you insert it into the database

So if you want to log the player in, If using MySQL plugin, as I stated above, you are doing it wrong because the password is invalid, you should use cache_get_value_name or cache_get_field_content depends on your MySQL plugin version to get the password's value and store it in the player Password variable. Then in the login dialog you use bcyrpt_check function and pass playerid as an argument , then in the callback you specified you create a boolean variable that has the value "bcrypt_is_equal" then check if the variable is true or false, and that's it

Hopefully that helps. If you didn't understand yet. I can share a code example
« Next Oldest | Next Newest »



  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Burgershot - Powered by our Community and MyBB Original Theme by Emerald

Linear Mode
Threaded Mode