mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2025-04-21 10:50:06 +00:00

* Merge kamilprzyb and main repo's code * Update Makefile by FunnHornhoover * Update Makefile by FinnHornhoover * Add flag to Makefile by FinnHornhoover * Remove extra line from makefile * Remove lbcrypt from Makefile * Fix flag to Makefile by FinnHornhoover * Reimplement potential fix for tutorial blackscreen by Dongresources * Update CMakeLists.txt * Update CMakeLists.txt * Reinsert Jade's changes * Cosmetic Changes to Databases .h & .cpp * Remove CMakeSettings.json * Update Makefile by Finn Hornhoover * More cosmetic changes to Databases.cpp * More cosmetic changes to Databases.cpp * Remove unnecessary line (CMakeSettings.json) * Fix CNLoginServer.cpp * More cosmetic Changes to Database.hpp, edit Database.cpp to use JSON library onstead of json11 library, and delete json11 library files * Delete json11 library files * Delete JSON library to reupload * Reupload JSON library from main repo * Reupload JSON library from main repo * Fix syntax error * Fix Makefile * Remove commented line of code to be like master Co-authored-by: CPunch <sethtstubbs@gmail.com>
32 lines
843 B
C++
32 lines
843 B
C++
#ifndef __BCRYPT__
|
|
#define __BCRYPT__
|
|
|
|
#ifdef _WIN32
|
|
#include "winbcrypt.h"
|
|
#else
|
|
|
|
#include "bcrypt.h"
|
|
#include <string>
|
|
#include <stdexcept>
|
|
class BCrypt {
|
|
public:
|
|
static std::string generateHash(const std::string & password, int workload = 12){
|
|
char salt[BCRYPT_HASHSIZE];
|
|
char hash[BCRYPT_HASHSIZE];
|
|
int ret;
|
|
ret = bcrypt_gensalt(workload, salt);
|
|
if(ret != 0)throw std::runtime_error{"bcrypt: can not generate salt"};
|
|
ret = bcrypt_hashpw(password.c_str(), salt, hash);
|
|
if(ret != 0)throw std::runtime_error{"bcrypt: can not generate hash"};
|
|
return std::string{hash};
|
|
}
|
|
|
|
static bool validatePassword(const std::string & password, const std::string & hash){
|
|
return (bcrypt_checkpw(password.c_str(), hash.c_str()) == 0);
|
|
}
|
|
};
|
|
|
|
#endif
|
|
|
|
#endif // __BCRYPT__
|