Skip to content

Commit c632874

Browse files
committed
modify:user pass now support get and set
1 parent 816302a commit c632874

File tree

3 files changed

+47
-13
lines changed

3 files changed

+47
-13
lines changed

XEngine_Apps/Authorize_APPClient/Authorize_APPClient.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ using namespace std;
3535
//Linux::g++ -std=c++17 -Wall -g Authorize_APPClient.cpp -o Authorize_APPClient.exe -I ../../XEngine_Source/XEngine_Depend/XEngine_Module/jsoncpp -L ../../XEngine_Release -lXEngine_OPenSsl -lXClient_Socket -lXEngine_BaseLib -lXClient_APIHelp -lpthread -ljsoncpp -Wl,-rpath=../../XEngine_Release
3636

3737
//#define _DYNAMIC_CODE
38+
//#define _PASS_ENCRYPT
3839
bool bRun = true;
3940
bool bLogin = true;
4041
bool bTimeOut = true;
@@ -244,6 +245,14 @@ int AuthClient_Login()
244245
strcpy(st_AuthUser.tszUserName, lpszUser);
245246
strcpy(st_AuthUser.tszUserPass, lpszPass);
246247

248+
#ifdef _PASS_ENCRYPT
249+
int nPLen = _tcsxlen(st_AuthUser.tszUserPass);
250+
XBYTE byMD5Buffer[MAX_PATH] = {};
251+
OPenSsl_Api_Digest(st_AuthUser.tszUserPass, byMD5Buffer, &nPLen, false, XENGINE_OPENSSL_API_DIGEST_MD5);
252+
memset(st_AuthUser.tszUserPass, '\0', sizeof(st_AuthUser.tszUserPass));
253+
BaseLib_OperatorString_StrToHex((LPCXSTR)byMD5Buffer, nPLen, st_AuthUser.tszUserPass);
254+
#endif
255+
247256
if (nDYCode > 0)
248257
{
249258
st_ProtocolHdr.xhToken = xhToken;

XEngine_Release/XEngine_Config/XEngine_Config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"tszKeyPass":"123123qa"
2525
},
2626
"st_PassCrypto":{
27-
"bEnable":true,
27+
"bEnable":false,
2828
"nCodec":2
2929
},
3030
"st_XToken":{

XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/AuthorizeHTTP_Post/AuthorizeHTTP_User.cpp

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -206,50 +206,75 @@ bool XEngine_AuthorizeHTTP_User(XNETHANDLE xhToken, LPCXSTR lpszClientAddr, LPCX
206206
{
207207
AUTHREG_USERTABLE st_UserTable;
208208
XENGINE_PROTOCOL_USERINFO st_UserInfo;
209-
XENGINE_PROTOCOL_USERAUTH st_AuthProtocol;
210-
209+
211210
memset(&st_UserTable, '\0', sizeof(AUTHREG_USERTABLE));
212211
memset(&st_UserInfo, '\0', sizeof(XENGINE_PROTOCOL_USERINFO));
213-
memset(&st_AuthProtocol, '\0', sizeof(XENGINE_PROTOCOL_USERAUTH));
214-
212+
215213
if (!st_FunSwitch.bSwitchPass)
216214
{
217215
Protocol_Packet_HttpComm(tszSDBuffer, &nSDLen, 503, "the function is closed");
218216
XEngine_Client_TaskSend(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_AUTH_APP_NETTYPE_HTTP);
219-
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("HTTP客户端:%s,找回密码失败,密码找回功能已经被服务器关闭!"), lpszClientAddr);
217+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("HTTP客户端:%s,找回重置密码失败,密码找回重置功能已经被服务器关闭!"), lpszClientAddr);
220218
return false;
221219
}
222220
Protocol_Parse_HttpParseUser(lpszMsgBuffer, nMsgLen, &st_UserInfo);
221+
//得到数据库信息
223222
bool bSuccess = false;
224-
if (0 == st_AuthConfig.st_XSql.nDBType)
223+
if (0 == st_AuthConfig.st_XSql.nDBType)
225224
{
226225
bSuccess = DBModule_SQLite_UserQuery(st_UserInfo.tszUserName, &st_UserTable);
227226
}
228-
else
227+
else
229228
{
230229
bSuccess = DBModule_MySQL_UserQuery(st_UserInfo.tszUserName, &st_UserTable);
231230
}
232-
if (!bSuccess)
231+
if (!bSuccess)
233232
{
234233
Protocol_Packet_HttpComm(tszSDBuffer, &nSDLen, 404, "user not found");
235234
XEngine_Client_TaskSend(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_AUTH_APP_NETTYPE_HTTP);
236-
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("HTTP客户端:%s,用户名:%s,找回密码失败,用户不存在"), lpszClientAddr, st_UserInfo.tszUserName);
235+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("HTTP客户端:%s,用户名:%s,找回重置密码失败,用户不存在"), lpszClientAddr, st_UserInfo.tszUserName);
237236
return false;
238237
}
239238
//安全验证判断
240239
if ((0 != _tcsxnicmp(st_UserInfo.tszEMailAddr, st_UserTable.st_UserInfo.tszEMailAddr, _tcsxlen(st_UserInfo.tszEMailAddr))) || (st_UserTable.st_UserInfo.nIDNumber != st_UserInfo.nIDNumber))
241240
{
242241
Protocol_Packet_HttpComm(tszSDBuffer, &nSDLen, 400, "user information is incorrent");
243242
XEngine_Client_TaskSend(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_AUTH_APP_NETTYPE_HTTP);
244-
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("HTTP客户端:%s,用户名:%s,找回密码失败,验证信息失败"), lpszClientAddr, st_UserInfo.tszUserName);
243+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("HTTP客户端:%s,用户名:%s,找回重置密码失败,验证信息失败"), lpszClientAddr, st_UserInfo.tszUserName);
245244
return false;
246245
}
246+
//是否开启了密码加密
247+
if (st_AuthConfig.st_XVerification.st_PassCrypto.bEnable)
248+
{
249+
//开启了,密码重置
250+
int nPLen = _tcsxlen(st_UserInfo.tszUserPass);
251+
XBYTE byMD5Buffer[MAX_PATH] = {};
252+
OPenSsl_Api_Digest(st_UserInfo.tszUserPass, byMD5Buffer, &nPLen, false, st_AuthConfig.st_XVerification.st_PassCrypto.nCodec);
253+
memset(st_UserTable.st_UserInfo.tszUserPass, '\0', sizeof(st_UserTable.st_UserInfo.tszUserPass));
254+
BaseLib_OperatorString_StrToHex((LPCXSTR)byMD5Buffer, nPLen, st_UserTable.st_UserInfo.tszUserPass);
255+
//重置密码
256+
if (0 == st_AuthConfig.st_XSql.nDBType)
257+
{
258+
bSuccess = DBModule_SQLite_UserSet(&st_UserTable);
259+
}
260+
else
261+
{
262+
bSuccess = DBModule_MySQL_UserSet(&st_UserTable);
263+
}
264+
if (!bSuccess)
265+
{
266+
Protocol_Packet_HttpComm(tszSDBuffer, &nSDLen, 404, "not found client");
267+
XEngine_Client_TaskSend(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_AUTH_APP_NETTYPE_HTTP);
268+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("HTTP客户端:%s,请求修改密码失败:%s 错误码:%lX"), lpszClientAddr, st_UserTable.st_UserInfo.tszUserName, DBModule_GetLastError());
269+
return false;
270+
}
271+
}
272+
XENGINE_PROTOCOL_USERAUTH st_AuthProtocol = {};
247273
_tcsxcpy(st_AuthProtocol.tszUserName, st_UserTable.st_UserInfo.tszUserName);
248274
_tcsxcpy(st_AuthProtocol.tszUserPass, st_UserTable.st_UserInfo.tszUserPass);
249-
250275
Protocol_Packet_HttpUserPass(tszSDBuffer, &nSDLen, &st_AuthProtocol);
251276
XEngine_Client_TaskSend(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_AUTH_APP_NETTYPE_HTTP);
252-
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("HTTP客户端:%s,用户名:%s,找回密码成功"), lpszClientAddr, st_UserInfo.tszUserName);
277+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("HTTP客户端:%s,用户名:%s,找回重置密码成功"), lpszClientAddr, st_UserInfo.tszUserName);
253278
}
254279
else if (0 == _tcsxnicmp(lpszAPIName, lpszAPITry, _tcsxlen(lpszAPIName)))
255280
{

0 commit comments

Comments
 (0)