hash users paswords
This commit is contained in:
parent
df772fec57
commit
a21f94bb69
@ -1,5 +1,9 @@
|
||||
#include "msql_acces.h"
|
||||
#include <iostream>
|
||||
#include <openssl/sha.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <string.h>
|
||||
|
||||
msql_acces::msql_acces()
|
||||
{
|
||||
driver = get_driver_instance();
|
||||
@ -103,10 +107,14 @@ bool msql_acces::get_package_exists(std::string package){
|
||||
|
||||
void msql_acces::create_user(std::string user, std::string pass, bool admin){
|
||||
sql::PreparedStatement *pstmt = con->prepareStatement("insert into users(username, passwd, admin) values(?, ?, ?)");
|
||||
unsigned char hash[SHA512_DIGEST_LENGTH];
|
||||
SHA512(reinterpret_cast<unsigned const char*>(pass.data()), strlen(pass.data()), hash);
|
||||
unsigned char encodedData[200];
|
||||
EVP_EncodeBlock(encodedData, hash, sizeof (hash));
|
||||
pstmt->setString(1,user);
|
||||
pstmt->setString(2,pass);
|
||||
pstmt->setString(2,std::string(reinterpret_cast<char*>(encodedData)));
|
||||
pstmt->setBoolean(3,admin);
|
||||
sql::ResultSet *res = pstmt->executeQuery();
|
||||
pstmt->executeQuery();
|
||||
}
|
||||
|
||||
void msql_acces::remove_user(std::string user){
|
||||
|
@ -5,6 +5,8 @@
|
||||
#include <sys/wait.h>
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
#include <openssl/sha.h>
|
||||
#include <openssl/evp.h>
|
||||
|
||||
session_manager::session_manager(int fd)
|
||||
{
|
||||
@ -17,7 +19,12 @@ bool session_manager::validate_pass(){
|
||||
this->read_data(buffer, 256);
|
||||
std::string user=buffer;
|
||||
this->read_data(buffer, 256);
|
||||
std::string pass=buffer;
|
||||
// std::string pass=buffer;
|
||||
unsigned char hash[SHA512_DIGEST_LENGTH];
|
||||
SHA512(reinterpret_cast<unsigned const char*>(buffer), strlen(buffer), hash);
|
||||
unsigned char encodedData[200];
|
||||
EVP_EncodeBlock(encodedData, hash, sizeof (hash));
|
||||
std::string pass=std::string(reinterpret_cast<char*>(encodedData));
|
||||
if(this->data->get_passwd(user)==pass){
|
||||
this->write_data("pass");
|
||||
if(this->data->get_admin(user)){
|
||||
|
Loading…
Reference in New Issue
Block a user