samp.directory
← Scripts e bibliotecas

Se8870/pp-bcrypt

PawnPlus for BCrypt, support both lib (Lassir and SyS)

Biblioteca★ 1atualizado nov. de 2021MITPawnsampctl
Abrir no GitHub

Instalar com o sampctl

sampctl package install Se8870/pp-bcrypt

Execute na pasta do seu projeto. O sampctl baixa o pacote e as dependências dele.

Depende de 3 pacotes

README.md

PawnPlus BCrypt

PawnPlus BCrypt is a library to make hashing and checking more easy with a help of Task & Await from PawnPlus.

This implementations originally took from Mergevos, but his version doesn't support SyS Bcrypt. Since i don't want to break his work, i decided to make this repo to distinguish between his version and mine.

Installation

Simply install to your project:

sampctl package install Kirima2nd/pp-bcrypt

Include in your code after PawnPlus.inc and BCrypt include, then you can begin using the library:

#include <PawnPlus>
#include <samp_bcrypt>

#include <pp-bcrypt>

Function Lists

/*
    Hashing
    - returns string hash with BCRYPT_HASH_LENGTH size
    - returns Dynamic String
*/
stock Task:BCrypt_AsyncHash(const input[], cost = BCRYPT_COST);
stock Task:BCrypt_AsyncHashStr(ConstStringTag:input, cost = BCRYPT_COST);

/* 
    Verifying
    - Returns integer/number (success can be 0 and 1)
*/
stock Task:BCrypt_AsyncVerify(const input[], const hash[]);
stock Task:BCrypt_AsyncVerifyStr(ConstStringTag:input, ConstStringTag:hash);

Usage

Normal string usage:

#include <PawnPlus>
#include <samp_bcrypt>

#include <pp-bcrypt>

main()
{
    new x_result[BCRYPT_HASH_LENGTH];
    await_str(x_result) BCrypt_AsyncHash("Hello World!");
    new ret = await BCrypt_AsyncVerify("Hello World!", x_result);

    printf("Result naked: %s", x_result);
    printf("Result same?: %s", ret ? "Yes" : "No");
}

Dynamic String usage:

main()
{
    new String:hash = await_str_s BCrypt_AsyncHashStr(str_new_static("Helo World!"), 12);
    pawn_guard(hash);

    new ret = await BCrypt_AsyncVerifyStr(str_new_static("Helo World!"), hash);

    new hash_str[BCRYPT_HASH_LENGTH];
    str_get(hash, hash_str);

    printf("Result naked: %s", hash_str);
    printf("Result same?: %s", ret ? "Yes" : "No");
}

In Dynamic String usage, using pawn_guard is required for making sure that the hash will be destroyed at the end of main function. Without this the hash text can be destroyed when calling BCrypt_AsyncVerifyStr. But if you're already using str_acquire and decided to make the Dynamic String to be accessed globally, then no need to use pawn_guard.

Testing

To test, simply run the package:

sampctl package run

Credits

  • Mergevos - async-bcrypt (It give me inspiration to make this one)
  • Grabber - pp-mysql (the pp logic basically from his include)
  • IllidanS4 - PawnPlus

Esta página é montada com o que o GitHub publica sobre o repositório. O samp.directory não hospeda o código. Avisar de um problema com esta página