1

I have downloaded https://github.com/alecgn/crypthash-net and moved it to the project's folder.This project is saved in main.cpp.

#include <CryptHash/CryptHash.h>
#include <bcrypt.h>
using namespace bcrypt;




class SecureEncryptor {
public:
static std::string hash_password(const std::string& password) {
Generate a random salt
std::string salt = generate_salt();
// Concatenate salt and password, then hash using bcrypt
std::string salted_password = salt + password;
std::string hashed_password = bcrypt::generateHash(salted_password);

// Store salt and hashed password securely in your database

return salt + hashed_password;
}

static bool verify_password(const std::string& password, const std::string& stored_password) {

// Extract salt from stored_password

std::string salt = stored_password.substr(0, BCRYPT_HASHSIZE);

// Concatenate salt and entered password, then hash using bcrypt

std::string salted_password = salt + password;
std::string hashed_password = bcrypt::generateHash(salted_password);

// Compare the hashed passwords

return stored_password == (salt + hashed_password);
}

private:
static std::string generate_salt() {

// Generate a secure random salt using bcrypt

return bcrypt::generateSalt();
}
};

Please tell me step by step to download the bcypt file and connect it to the project and mysql, Xampp

2
  • 2
    This is a C# library? Commented Dec 10, 2023 at 8:11
  • Yes it is a C# library and thus not (directly) usable from C++ Commented Dec 10, 2023 at 8:38

2 Answers 2

1

Friend, I'm the owner of CryptHash.NET lib; this is a .NET library, so, you can't use it with C++. Thanks by being interested in it, but I recommend you to consider/find a cpp library, as the others have said, unless you find a C# to cpp bride / interface of some kind, you will not be able to use it, but I personally don't recommend that, it's not worth the work you'll have.

Sign up to request clarification or add additional context in comments.

Comments

0

friend,

this is a C# library. So the awnser is you can't. Unless you find a C# to cpp bride / interface of some kind. Otherwise you may want to consider a different cpp library for your task.

1 Comment

There is a .net version of c++, see learn.microsoft.com/en-us/cpp/dotnet/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.