Jump to content
  • 0

Sistem de criptare parole


Question

Posted

Salut, am nevoie de ajutor cu sistemul de criptare, sunt incepator si nu stiu prea multe.

2 answers to this question

Recommended Posts

  • 0
Posted

Ceea ce cauti tu nu se numeste criptare, ci hasurare pentru ca la criptare vei avea nevoie de o parola in plus doar pentru a decripta in schimb la hashurare este in inclus direct in string rezultat

Ai probleme cu cel actual sau doresti sa implementezi acest sistem? Daca ai probleme cu cel actual doar specifica ce anume nu merge si ce erori intampini

Daca vrei sa implementezi unul iti recomand bcrypt https://github.com/lassir/bcrypt-samp

#include <a_samp>
#include <bcrypt>

#define BCRYPT_COST 12

forward OnPasswordHashed(playerid);
forward OnPasswordChecked(playerid);
 
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        case DIALOG_REGISTRATION:
        {
			bcrypt_hash(inputtext, BCRYPT_COST, "OnPasswordHashed", "d", playerid);
        }

        case DIALOG_LOGIN:
        {
            // Variable hash is expected to contain the hash loaded from the database
            bcrypt_check(inputtext, hash,  "OnPasswordChecked", "d", playerid);
        }
    }

    return 1;
}

public OnPasswordHashed(playerid)
{
	new hash[BCRYPT_HASH_LENGTH];
	bcrypt_get_hash(hash);
	
	printf("Password hashed for player %d: %s", playerid, hash);
	return 1;
}

public OnPasswordChecked(playerid)
{
	new bool:match = bcrypt_is_equal();
	
	printf("Password checked for %d: %s", (match) ? ("Match") : ("No match"));
	return 1;
}

Acest cod l-am luat direct din exemplul oferit in link acela de la bcrypt. Esssential ce ar trebui sa faci la DIALOG_LOGIN este sa extragi parola curenta din baza de date inainte sa chemi bcrypt_check astfel incat sa se poate verifica si eventual la register sa inserezi/actualizezi parola playerului care tocmai ce si-a facut la OnPasswordHashed astfel incat sa ai parola hashurata

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. For more details you can also review our Terms of Use and Privacy Policy.