samp.directory
← Skrypty i biblioteki

hreesang/samp-pp-bcrypt

A library that features PawnPlus async-await to BCrypt plugins, works for both SA:MP and open.mp

Biblioteka★ 2zaktualizowano wrz 2023Brak licencjiPawnsampctl
Otwórz na GitHubie

To repozytorium nie ma pliku licencji. Jest publiczne do odczytu, ale samo to nie daje pozwolenia na ponowne użycie.

Zainstaluj za pomocą sampctl

sampctl package install hreesang/samp-pp-bcrypt

Uruchom to w folderze swojego projektu. sampctl pobiera pakiet i to, od czego zależy.

Wypróbuj w kompilatorze Pawn →

Dodaje jej pliki include, razem z bibliotekami, od których zależy, do kompilatora Pawn w twojej przeglądarce, gotowe do dołączenia w skrypcie.

Zależy od 1 pakietu

README.md

samp-pp-bcrypt

This library expands the usage of BCrypt plugins in SA:MP or open.mp for PawnPlus async-await features. You're free to use either Sryeas-Sreelal/samp-bcrypt or lassir/bcrypt-samp as both are supported and the usage is the same, so you don't need to change functions or arguments when switching between plugins.

Installation

Simply install to your project:

sampctl install Hreesang/samp-pp-bcrypt

Include in your code and begin using the library:

#include <pp_bcrypt>

This library doesn't automatically install the supported BCrypt plugins, so you need to install them manually. You only need to choose one of them:

Usage

CMD:hash(playerid, const params[])
{
    if (isnull(params)) {
        return SendClientMessage(playerid, -1, "Usage: /hash [text]");
    }

    new hash[BCRYPT_HASH_LENGTH];
    yield 1;
    await_arr(hash) BCrypt_AsyncHash(params);

    new string[144];
    SendClientMessage(playerid, -1, "Command: /hash [text]");

    format(string, sizeof string, "Text: %s", params);
    SendClientMessage(playerid, -1, string);

    format(string, sizeof string, "Hash: %s", hash);
    SendClientMessage(playerid, -1, string);
    return 1;
}

CMD:verify(playerid, const params[])
{
    new hash[BCRYPT_HASH_LENGTH];
    new text[128];

    if (sscanf(params, "s[*]s[128]", sizeof hash, hash, text)) {
        return SendClientMessage(playerid, -1, "/verify [hash] [text]");
    }

    yield 1;
    new bool:isVerified = bool:await BCrypt_AsyncVerify(text, hash);

    new string[144];
    SendClientMessage(playerid, -1, "Command: /verify [hash] [text]");

    format(string, sizeof string, "Text: %s", text);
    SendClientMessage(playerid, -1, string);

    format(string, sizeof string, "Hash: %s", hash);
    SendClientMessage(playerid, -1, string);

    format(string, sizeof string, "Is Verified: %s", isVerified ? "Yes" : "No");
    SendClientMessage(playerid, -1, string);

    return 1;
}

Functions

BCrypt_AsyncHash
  • Parameters:
    • const input[]: input that needs to be hashed
    • cost = BCRYPT_COST: bcrypt cost, default to BCRYPT_COST that is 12.
  • Returns:
    • PawnPlus task whose result is an array sized BCRYPT_HASH_LENGTH
  • Remarks:
    • Returns the task that needs to be awaited
BCrypt_AsyncVerify
  • Parameters:
    • const input[]: plain text
    • const hash[]: hash that will be testified to input.
  • Returns:
    • PawnPlus task whose result is a true boolean if verified or false if not
  • Remarks:
    • Returns the verification result

Testing

To test, simply run the package:

sampctl run

Credits

Ta strona jest zbudowana z tego, co GitHub publikuje o repozytorium. samp.directory nie hostuje kodu. Zgłoś problem z tym wpisem

hreesang/samp-pp-bcrypt: Biblioteka SA-MP | samp.directory