更新登录用户获取信息
parent
9329eb662c
commit
3f17997af2
|
@ -2,6 +2,7 @@
|
|||
#include <cgicc/CgiDefs.h>
|
||||
#include <cgicc/HTTPHTMLHeader.h>
|
||||
#include <cgicc/HTMLClasses.h>
|
||||
#include <hv/hv.h>
|
||||
|
||||
#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);
|
||||
|
|
|
@ -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<sql::PreparedStatement> pstmt(pDbConnection->prepareStatement(sql));
|
||||
std::unique_ptr<sql::PreparedStatement> 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;
|
||||
|
|
Loading…
Reference in New Issue