database functions
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
#include <crypt.h>
|
||||
#include <stdexcept>
|
||||
#include "hashing.hpp"
|
||||
#include <random>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
std::string hashing::GenerateSetting(unsigned long cost) {
|
||||
// "$y$" is the yescrypt prefix
|
||||
@@ -24,4 +27,18 @@ bool hashing::VerifyPassword(const std::string& password, const std::string& sto
|
||||
if (!result || result[0] == '*')
|
||||
return false;
|
||||
return stored_hash == result;
|
||||
}
|
||||
|
||||
std::string hashing::generate_token(size_t bytes) {
|
||||
std::random_device rd;
|
||||
std::string token;
|
||||
token.reserve(bytes * 2);
|
||||
|
||||
std::uniform_int_distribution<uint8_t> dist(0, 255);
|
||||
for (size_t i = 0; i < bytes; ++i) {
|
||||
std::ostringstream ss;
|
||||
ss << std::hex << std::setw(2) << std::setfill('0') << (int)dist(rd);
|
||||
token += ss.str();
|
||||
}
|
||||
return token;
|
||||
}
|
||||
Reference in New Issue
Block a user