I try to write a simple login script using bcrypt. I've tried to use the C wrapper libbcrypt library - https://github.com/trusch/libbcrypt - but got stuck with the compiler complaining about undefined references to bcrypt_checkpw, bcrypt_hashpw, bcrypt_gensalt in the BCrypt class.
First thing I've done was to follow the instructions from the readme.md - https://github.com/trusch/libbcrypt/blob/master/README.md :
git clone https://github.com/trusch/libbcrypt
cd libbcrypt
mkdir build
cd build
cmake ..
make
sudo make install
sudo ldconfig
Then I have my main.cpp file
#include <iostream>
#include "User_Class.hpp"
void checkPermission();
int main(int argc, char* argv[]) {
checkPermission();
return 0;
}
void checkPermission() {
User_Class User;
User.Login("test");
}
My User_Class.cpp file
#include <iostream>
#include "Password_Class.hpp"
#include "User_Class.hpp"
bool User_Class::Login(std::string password) {
return Password_Class::authenticate(password);
}
My User_Class.hpp file
class User_Class {
public:
bool Login(std::string password);
};
My Password_Class.cpp file
#include <iostream>
#include "Password_Class.hpp"
#include "bcrypt/BCrypt.hpp"
bool Password_Class::authenticate(std::string password) {
// this fails!
std::string hash = BCrypt::generateHash(password);
std::cout << BCrypt::validatePassword(password,hash) << std::endl;
return true;
}
And my Password_Class.hpp file
class Password_Class {
public:
static bool authenticate(Glib::ustring password);
};
When compiling with this command
g++ -lbcrypt main.cpp User_Class.cpp Password_Class.cpp -o main `pkg-config --libs --cflags gtkmm-3.0`
I get errors
/tmp/ccc3Va1h.o: In Funktion »BCrypt::generateHash(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)«:
Password_Class.cpp:(.text._ZN6BCrypt12generateHashERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEi[_ZN6BCrypt12generateHashERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEi]+0x44): Warnung: undefinierter Verweis auf »bcrypt_gensalt«
Password_Class.cpp:(.text._ZN6BCrypt12generateHashERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEi[_ZN6BCrypt12generateHashERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEi]+0xb0): Warnung: undefinierter Verweis auf »bcrypt_hashpw«
/tmp/ccc3Va1h.o: In Funktion »BCrypt::validatePassword(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)«:
Password_Class.cpp:(.text._ZN6BCrypt16validatePasswordERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES7_[_ZN6BCrypt16validatePasswordERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES7_]+0x33): Warnung: undefinierter Verweis auf »bcrypt_checkpw«
collect2: error: ld returned 1 exit status
So please can someone tell me what's going on here? What have I done wrong so how do I use bcrypt in C++? I guess some libraries couldn't be found but I'm really no expert in linux or C++ so please forgive me ;)
Thank you for your help!