Jump to content
  • 0

Sistem de criptare parole


IonutIBM

Question

2 answers to this question

Recommended Posts

  • 0

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.