- Mesaj
- 101
- Çözümler
- 3
- Beğeni
- 136
- Puan
- 369
- Ticaret Puanı
- 0
Mariadb güncellemesi sonrasında hesap bulunamadı hesap ismi veya şifre yanlış problemi için çözüm
utils.cpp
Arat:
#ifndef __WIN32__
#include <mysql/mysql.h>
#ifndef SHA1_HASH_SIZE
#define SHA1_HASH_SIZE 20
#endif
#ifdef WIN32
extern "C" void my_make_scrambled_password(char* to, const char* password, size_t pass_len);
#endif
std::string mysql_hash_password(const char* tmp_pwd)
{
char hash_buf[2 * SHA1_HASH_SIZE + 2] = "";
#ifdef WIN32
my_make_scrambled_password(hash_buf, tmp_pwd, strlen(tmp_pwd));
#else
make_scrambled_password(hash_buf, tmp_pwd);
#endif
return hash_buf;
}
#endif
Değiştir:
#include <iostream>
#include <string>
#include <iomanip>
#include <cryptopp/cryptlib.h>
#include <cryptopp/filters.h>
#include <cryptopp/hex.h>
#include <cryptopp/sha.h>
std::string mysql5_password(const std::string& input)
{
CryptoPP::SHA1 sha1;
CryptoPP::byte digest1[CryptoPP::SHA1::DIGESTSIZE];
// First SHA1 hash
sha1.Update(reinterpret_cast<const CryptoPP::byte*>(input.c_str()), input.length());
sha1.Final(digest1);
// Second SHA1 hash on the hex-encoded digest1
std::string encoded1(reinterpret_cast<const char*>(digest1), CryptoPP::SHA1::DIGESTSIZE);
std::string encoded2;
CryptoPP::StringSource(encoded1, true,
new CryptoPP::HashFilter(sha1,
new CryptoPP::HexEncoder(
new CryptoPP::StringSink(encoded2)
)
)
);
// Uppercase and prepend '*'
std::string password = "*" + encoded2;
for (char& c : password) {
c = std::toupper(c);
}
return password;
}
std::string mysql_hash_password(const char* tmp_pwd)
{
return mysql5_password(tmp_pwd);
}