From 3f17997af261c257b6ad198fb9b9670dcfa0e1af Mon Sep 17 00:00:00 2001 From: HwangKC Date: Fri, 7 Jun 2024 16:44:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=99=BB=E5=BD=95=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E8=8E=B7=E5=8F=96=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- applications/WebConfigure/cgiCommon/main.cpp | 9 ++++++++ .../WebConfigure/cgiCommon/opmysql.cpp | 23 +++++++++++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/applications/WebConfigure/cgiCommon/main.cpp b/applications/WebConfigure/cgiCommon/main.cpp index 6adc0ec..9fea345 100644 --- a/applications/WebConfigure/cgiCommon/main.cpp +++ b/applications/WebConfigure/cgiCommon/main.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include "handleHeader.h" @@ -80,6 +81,14 @@ int main() using namespace cgicc; using namespace std; + hlog_set_file("/var/log/webcfg.log"); + hlog_set_level_by_str("DEBUG"); + hlog_set_max_filesize_by_str("16M"); + hlog_set_remain_days(10); + logger_enable_fsync(hlog, 1); + //hlogi("=========--- Welcome to the Earth ---========="); + hlog_fsync(); + Cgicc formData; #if 0 handleLoginRequest(formData); diff --git a/applications/WebConfigure/cgiCommon/opmysql.cpp b/applications/WebConfigure/cgiCommon/opmysql.cpp index 18be558..5dd9a95 100644 --- a/applications/WebConfigure/cgiCommon/opmysql.cpp +++ b/applications/WebConfigure/cgiCommon/opmysql.cpp @@ -23,6 +23,7 @@ OpDatabase::~OpDatabase() //CloseDatabase(); } + std::string OpDatabase::CalculateMD5(const std::string& data) { char md5_str[33] = { 0 }; @@ -121,6 +122,7 @@ bool OpDatabase::queryUser(const std::string& user_id, const std::string& passwd { try { +#if 0 // 数据库连接配置 std::string server = "tcp://127.0.0.1:3306"; std::string dbuser = "root"; @@ -142,12 +144,12 @@ bool OpDatabase::queryUser(const std::string& user_id, const std::string& passwd // 设置为使用指定数据库 pDbConnection->setSchema(database); hloge("%s : %s", user_id.c_str(), passwd_md5.c_str()); - +#endif // 准备SQL查询语句 std::string sql = "SELECT uid,uname, upasswd,usalt,email,mobile1,mobile2,memo FROM tbl_user WHERE uid = ?"; // 创建预编译的prepared statement - std::unique_ptr pstmt(pDbConnection->prepareStatement(sql)); + std::unique_ptr pstmt(m_pDbConnection->prepareStatement(sql)); // 绑定参数 pstmt->setString(1, user_id); // 替换为你要查询的用户名 @@ -174,9 +176,16 @@ bool OpDatabase::queryUser(const std::string& user_id, const std::string& passwd //计算passwd和salt之间的关系 //!passwd=md5(passwd_md5+salt+salt) - std::string tmp = passwd_md5 + salt + salt; + // passwd_md5 是大写的,需要确保一下 + std::string tmp2(passwd_md5); + std::transform(tmp2.begin(), tmp2.end(), tmp2.begin(), + [](unsigned char c) + { + return std::toupper(c); + }); + + std::string tmp = tmp2 + salt + salt; std::string smd5 = CalculateMD5(tmp); - hloge("upass=[%s],cakc=[%s],src=[%s]", pass.c_str(),smd5.c_str(), tmp.c_str()); if (pass == smd5) { @@ -191,11 +200,15 @@ bool OpDatabase::queryUser(const std::string& user_id, const std::string& passwd ret = true; break; } + else + { + hloge("upass=[%s],calc=[%s],src=[%s]", pass.c_str(), smd5.c_str(), tmp.c_str()); + } } jsonResult = json.encode(); - pDbConnection->close(); + //pDbConnection->close(); //delete pDbConnection; return ret;