Username/Password Authentication for UI
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <openssl/pem.h>
|
||||
#include "crypto.h"
|
||||
#include <iostream>
|
||||
namespace crypto {
|
||||
using big_num_t = util::safe_ptr<BIGNUM, BN_free>;
|
||||
//using rsa_t = util::safe_ptr<RSA, RSA_free>;
|
||||
@@ -338,4 +339,24 @@ bool verify256(const x509_t &x509, const std::string_view &data, const std::stri
|
||||
void md_ctx_destroy(EVP_MD_CTX *ctx) {
|
||||
EVP_MD_CTX_destroy(ctx);
|
||||
}
|
||||
|
||||
std::string rand_string(std::size_t bytes)
|
||||
{
|
||||
std::string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!%&()=-";
|
||||
std::string value = rand(bytes);
|
||||
for (std::size_t i = 0; i != value.size(); ++i) {
|
||||
value[i] = alphabet[value[i] % alphabet.length()];
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
std::string hash_hexstr(const std::string_view &plaintext)
|
||||
{
|
||||
sha256_t hashBytes = crypto::hash(plaintext);
|
||||
std::ostringstream hashStream;
|
||||
hashStream << std::hex << std::setfill( '0' );
|
||||
std::for_each( hashBytes.cbegin(), hashBytes.cend(), [&]( int c ) { hashStream << std::setw( 2 ) << c; } );
|
||||
std::string hashString = hashStream.str();
|
||||
return hashString;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user