sha256 hashing password
This commit is contained in:
1 parent
1513a05904
commit
1d7b443697
3 files changed
+26
-2
No files matched your search
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <openssl/sha.h>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
|
||||
// funcion for hashing password using sha256
|
||||
std::string hashPassword(const std::string &password) {
|
||||
unsigned char hash[SHA256_DIGEST_LENGTH];
|
||||
|
||||
// calculating hash
|
||||
SHA256(reinterpret_cast<const unsigned char*>(password.c_str()), password.size(), hash);
|
||||
|
||||
// reinterpreter as hex string
|
||||
std::stringstream ss;
|
||||
for (int i = 0; i < SHA256_DIGEST_LENGTH; ++i) {
|
||||
ss << std::setw(2) << std::setfill('0') << std::hex << static_cast<int>(hash[i]);
|
||||
}
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
Reference in new issue
Block a user