A c++ wrapper for libxcrypt around bcrypt password hashing
To compile this library if you use c++ std less than 20, you need to install below libraries:
- fmt 11.0.2 or greater
pacman -S fmt
or
paru -S fmt
apt-get install libfmt-dev
cmake ... -DWITH_CONAN=ON
or
conan create . --build=missing- CMake package name:
bcryptcpp - CMake target name:
bcryptcpp::bcryptcpp
A simple use case using the CMake file name and the global target:
find_package(bcryptcpp REQUIRED) # ... target_link_libraries(YOUR_TARGET bcryptcpp::bcryptcpp)
For an example of use, see the ./test folder
#include <bcryptcpp/bcryptcpp.hpp> ... std::string passwd = "12345"; std::string hash = bcrypt::hash (passwd, bcrypt::gensalt (12)); ... bool valid = bcrypt::compare (hash, passwd);
#include <iostream> ... try { // invalid hash valid = bcrypt::compare("12345", passwd); } catch (const bcrypt::exception::compare &e) { std::cerr << e.what() << "\n"; }