From 6a50daac547ebaf0c2503803626e12fbc63c0bb6 Mon Sep 17 00:00:00 2001 From: yanjinhui <3306209981@qq.com> Date: 星期四, 28 八月 2025 10:13:45 +0800 Subject: [PATCH] 修改密码的复杂度 --- 项目代码/后端/WCS/WIDESEAWCS_Server/WIDESEAWCS_SystemServices/Sys_UserService.cs | 233 +++++++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 166 insertions(+), 67 deletions(-) diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/\345\220\216\347\253\257/WCS/WIDESEAWCS_Server/WIDESEAWCS_SystemServices/Sys_UserService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/\345\220\216\347\253\257/WCS/WIDESEAWCS_Server/WIDESEAWCS_SystemServices/Sys_UserService.cs" index 8f4080e..5b2e79f 100644 --- "a/\351\241\271\347\233\256\344\273\243\347\240\201/\345\220\216\347\253\257/WCS/WIDESEAWCS_Server/WIDESEAWCS_SystemServices/Sys_UserService.cs" +++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/\345\220\216\347\253\257/WCS/WIDESEAWCS_Server/WIDESEAWCS_SystemServices/Sys_UserService.cs" @@ -14,10 +14,13 @@ using Microsoft.AspNetCore.Http; using Newtonsoft.Json; using WIDESEAWCS_Common; + using FaceAI; using System.Runtime.InteropServices; using System.IO; using WIDESEAWCS_DTO.Telescopic; +using System.Reflection.PortableExecutable; +using Microsoft.AspNetCore.Mvc; namespace WIDESEAWCS_SystemServices { @@ -31,9 +34,11 @@ private readonly IRepository<Dt_Maintenance> _MainServer; private readonly IRepository<Sys_Role> _RoleServer; private readonly IRepository<Dt_AuthorizationRecord> _AuthorizatRecServer; + private readonly IRepository<Sys_UserFace> _userFace; - public Sys_UserService(IRepository<Dt_AuthorizationRecord> AuthorizatRecServer,IRepository<Sys_Role> RoleServer,IRepository<Dt_Loginhsy> LoginhsyServer,IRepository<Dt_FaceRecognition> faceServer, IRepository<Sys_User> repository, IUnitOfWorkManage unitOfWorkManage, ICacheService cacheService, ISys_MenuService menuService, IRepository<Dt_Maintenance> MainServer) : base(repository) + public Sys_UserService(IRepository<Sys_UserFace> userFace,IRepository<Dt_AuthorizationRecord> AuthorizatRecServer,IRepository<Sys_Role> RoleServer,IRepository<Dt_Loginhsy> LoginhsyServer,IRepository<Dt_FaceRecognition> faceServer, IRepository<Sys_User> repository, IUnitOfWorkManage unitOfWorkManage, ICacheService cacheService, ISys_MenuService menuService, IRepository<Dt_Maintenance> MainServer) : base(repository) { + _userFace = userFace; _faceServer = faceServer; _LoginhsyServer = LoginhsyServer; _unitOfWorkManage = unitOfWorkManage; @@ -361,9 +366,26 @@ if (string.IsNullOrEmpty(oldPwd)) return WebResponseContent.Instance.Error("鏃у瘑鐮佷笉鑳戒负绌�"); if (string.IsNullOrEmpty(newPwd)) return WebResponseContent.Instance.Error("鏂板瘑鐮佷笉鑳戒负绌�"); if (newPwd.Length < 6) return WebResponseContent.Instance.Error("瀵嗙爜涓嶈兘灏戜簬6浣�"); + int userId = App.User.UserId; string userCurrentPwd = BaseDal.QueryFirst(x => x.User_Id == userId, s => s.UserPwd); + + // 鉁� 瀵嗙爜澶嶆潅搴︽牎楠岋細蹇呴』鍖呭惈瀛楁瘝鍜屾暟瀛� + // 鉁� 瀵嗙爜澶嶆潅搴︽牎楠岋細蹇呴』鍖呭惈澶у皬鍐欏瓧姣嶃�佹暟瀛楀拰鐗规畩绗﹀彿 + if (!global::System.Text.RegularExpressions.Regex.IsMatch(newPwd, @"[a-z]")) + return content.Error("鏂板瘑鐮佸繀椤诲寘鍚皬鍐欏瓧姣�"); + + if (!global::System.Text.RegularExpressions.Regex.IsMatch(newPwd, @"[A-Z]")) + return content.Error("鏂板瘑鐮佸繀椤诲寘鍚ぇ鍐欏瓧姣�"); + + if (!global::System.Text.RegularExpressions.Regex.IsMatch(newPwd, @"\d")) + return content.Error("鏂板瘑鐮佸繀椤诲寘鍚暟瀛�"); + + // 鉁� 瀵嗙爜澶嶆潅搴︽牎楠岋細蹇呴』鍖呭惈鑷冲皯涓�涓壒娈婄鍙凤紙闈炲瓧姣嶆暟瀛楃殑閮界畻锛� + if (!global::System.Text.RegularExpressions.Regex.IsMatch(newPwd, @"[^a-zA-Z0-9]")) + return content.Error("鏂板瘑鐮佸繀椤诲寘鍚嚦灏戜竴涓壒娈婄鍙�"); + string _oldPwd = oldPwd.EncryptDES(AppSecret.User); if (_oldPwd != userCurrentPwd) return WebResponseContent.Instance.Error("鏃у瘑鐮佷笉姝g‘"); @@ -399,7 +421,7 @@ /// <param name="id"></param> /// <param name="oldPwd"></param> /// <param name="newPwd"></param> - /// <returns></returns> + /// <returns></returns> public WebResponseContent UpdatePwd(int id, string oldPwd, string newPwd) { WebResponseContent content = new WebResponseContent(); @@ -408,22 +430,44 @@ try { - if (string.IsNullOrEmpty(oldPwd)) return content.Error("鏃у瘑鐮佷笉鑳戒负绌�"); - if (string.IsNullOrEmpty(newPwd)) return content.Error("鏂板瘑鐮佷笉鑳戒负绌�"); - if (newPwd.Length < 6) return content.Error("瀵嗙爜涓嶈兘灏戜簬6浣�"); + if (string.IsNullOrEmpty(oldPwd)) + return content.Error("鏃у瘑鐮佷笉鑳戒负绌�"); + + if (string.IsNullOrEmpty(newPwd)) + return content.Error("鏂板瘑鐮佷笉鑳戒负绌�"); + + if (newPwd.Length < 6) + return content.Error("瀵嗙爜涓嶈兘灏戜簬6浣�"); + + // 鉁� 瀵嗙爜澶嶆潅搴︽牎楠岋細蹇呴』鍖呭惈澶у皬鍐欏瓧姣嶃�佹暟瀛楀拰鐗规畩绗﹀彿 + if (!global::System.Text.RegularExpressions.Regex.IsMatch(newPwd, @"[a-z]")) + return content.Error("鏂板瘑鐮佸繀椤诲寘鍚皬鍐欏瓧姣�"); + + if (!global::System.Text.RegularExpressions.Regex.IsMatch(newPwd, @"[A-Z]")) + return content.Error("鏂板瘑鐮佸繀椤诲寘鍚ぇ鍐欏瓧姣�"); + + if (!global::System.Text.RegularExpressions.Regex.IsMatch(newPwd, @"\d")) + return content.Error("鏂板瘑鐮佸繀椤诲寘鍚暟瀛�"); + + // 鉁� 瀵嗙爜澶嶆潅搴︽牎楠岋細蹇呴』鍖呭惈鑷冲皯涓�涓壒娈婄鍙凤紙闈炲瓧姣嶆暟瀛楃殑閮界畻锛� + if (!global::System.Text.RegularExpressions.Regex.IsMatch(newPwd, @"[^a-zA-Z0-9]")) + return content.Error("鏂板瘑鐮佸繀椤诲寘鍚嚦灏戜竴涓壒娈婄鍙�"); // 鑾峰彇鐢ㄦ埛褰撳墠瀵嗙爜 string userCurrentPwd = BaseDal.QueryFirst(x => x.User_Id == id, s => s.UserPwd) ?? ""; - if (string.IsNullOrEmpty(userCurrentPwd)) return content.Error("鐢ㄦ埛涓嶅瓨鍦ㄦ垨瀵嗙爜鏈缃�"); + if (string.IsNullOrEmpty(userCurrentPwd)) + return content.Error("鐢ㄦ埛涓嶅瓨鍦ㄦ垨瀵嗙爜鏈缃�"); - //// 杩涜瀵嗙爜鍔犲瘑瀵规瘮 + //// 濡傛灉闇�瑕侀獙璇佹棫瀵嗙爜锛屾斁寮�杩欓噷 //string _oldPwd = oldPwd.EncryptDES(AppSecret.User); - //if (_oldPwd != userCurrentPwd) return content.Error("鏃у瘑鐮佷笉姝g‘"); + //if (_oldPwd != userCurrentPwd) + // return content.Error("鏃у瘑鐮佷笉姝g‘"); // 鐢熸垚鏂板瘑鐮佸姞瀵嗗�� string _newPwd = newPwd.EncryptDES(AppSecret.User); - if (userCurrentPwd == _newPwd) return content.Error("鏂板瘑鐮佷笉鑳戒笌鏃у瘑鐮佺浉鍚�"); + if (userCurrentPwd == _newPwd) + return content.Error("鏂板瘑鐮佷笉鑳戒笌鏃у瘑鐮佺浉鍚�"); // 鏇存柊瀵嗙爜 bool isUpdated = BaseDal.UpdateData(new Sys_User @@ -439,7 +483,7 @@ if (!isUpdated) { - return content.Error("瀵嗙爜淇敼澶辫触锛岃绋嶅悗閲嶈瘯"); + return content.Error("瀵嗙爜淇敼澶辫触锛屽瘑鐮佸繀椤诲寘鎷瓧姣嶄互鍙婄壒娈婂瓧绗�"); } return content.OK("瀵嗙爜淇敼鎴愬姛", id); @@ -566,7 +610,7 @@ RoleName = addUserDTO.rolename, Enable = addUserDTO.enable, Unit=addUserDTO.userunit, - UserPwd = "j79rYYvCz4vdhcboB1Ausg==", + UserPwd = "NgKc7vI5u5jzh115fowV~g==", Userteam=addUserDTO.userteam, Dept_Id=addUserDTO.dept_Id, //CardNumber=addUserDTO.carnuber, @@ -693,7 +737,7 @@ UserTeam = addUserDTO.userteam, EnableTime = addUserDTO.enable == 1 ? DateTime.Now : (DateTime?)null, //鍚敤 DisableTime = addUserDTO.enable == 0 ? DateTime.Now : (DateTime?)null,//涓嶅惎鐢� - + }; @@ -725,34 +769,43 @@ { try { + // 1. 妫�鏌ョ敤鎴锋槸鍚﹀瓨鍦� + var user = BaseDal.QueryData(x => x.UserName == account).FirstOrDefault(); + if (user == null) + { + return WebResponseContent.Instance.Error("鐢ㄦ埛涓嶅瓨鍦�"); + } - // 2. 鏌ヨ浜鸿劯搴撳垎缁� ID - //var faceGroupID = _faceServer.QueryData().Select(x => x.GroupID).FirstOrDefault(); - - //WIDESEAWCS_Common.DeleteUserImg deleteUserImg = new WIDESEAWCS_Common.DeleteUserImg(); - //deleteUserImg.group_id = faceGroupID; - //deleteUserImg.user_id = account; - - //string apiResult = BaiDuFaceHelper.DeleteUser(deleteUserImg);//鍙缁檛oken鍜宭og_id - - //// 2. 瑙f瀽杩斿洖缁撴灉锛屽垽鏂垹闄ゆ槸鍚︽垚鍔� - //dynamic resultObj = JsonConvert.DeserializeObject(apiResult); - //if (resultObj.error_code == 0) - //{ - // 鐧惧害鍒犻櫎鎴愬姛鍚庯紝鍒犻櫎鏁版嵁搴撲腑鐨勭敤鎴� - var user = BaseDal.QueryData(x => x.UserName == account).FirstOrDefault(); + // 2. 妫�鏌ヤ富璁板綍鏄惁瀛樺湪鍙婄姸鎬� var main = _MainServer.QueryData(x => x.UserAccount == account).FirstOrDefault(); - if (user != null&&main!=null) - { - BaseDal.DeleteData(user); + if (main == null) + { + return WebResponseContent.Instance.Error("鐢ㄦ埛涓昏褰曚笉瀛樺湪"); + } + if (main.MaintenanceStatus == 1) + { + return WebResponseContent.Instance.Error("璇ョ敤鎴疯繕鍦ㄦ淇腑锛屾棤娉曞垹闄�"); + } + + // 3. 妫�鏌ヤ汉鑴歌褰曟槸鍚﹀瓨鍦� + var face = _userFace.QueryFirst(x => x.UserName == account); + + // 4. 鎸夋潯浠跺垹闄� + if (face == null) + { + // 浠呭垹闄� user 鍜� main + BaseDal.DeleteData(user); _MainServer.DeleteData(main); } - return WebResponseContent.Instance.OK("鐢ㄦ埛鍒犻櫎鎴愬姛"); - //} - //else - //{ - // return WebResponseContent.Instance.Error("鐧惧害 API 鍒犻櫎澶辫触锛�" + resultObj.error_msg); - //} + else + { + // 鍒犻櫎鎵�鏈変笁涓褰� + _userFace.DeleteData(face); + BaseDal.DeleteData(user); + _MainServer.DeleteData(main); + } + + return WebResponseContent.Instance.OK("鐢ㄦ埛鍒犻櫎鎴愬姛"); } catch (Exception ex) { @@ -936,22 +989,27 @@ try { int totalCount = 0; - var Role = _RoleServer.Db.Queryable<Sys_Role>(); - var query = Role.InnerJoin<Sys_User>((a, b) => a.RoleId == b.Role_Id); + //var Role = _RoleServer.Db.Queryable<Sys_Role>(); + //var query = Role.InnerJoin<Sys_User>((a, b) => a.RoleId == b.Role_Id) + // .InnerJoin<Sys_UserFace>((a, b, c) => b.UserName == c.UserName); + + var User = BaseDal.Db.Queryable<Sys_User>(); //鏌ュ嚭鐢ㄦ埛琛� + var query = User.LeftJoin<Sys_UserFace>((a, b) => a.UserName == b.UserName); + //鎼滅储鍏抽敭瀛� if (!string.IsNullOrEmpty(pagination.searchKeyword)) { query = query.Where((a, b) => - b.UserName.Contains(pagination.searchKeyword) || - b.UserTrueName.Contains(pagination.searchKeyword) || - b.PhoneNo.Contains(pagination.searchKeyword) || + a.UserName.Contains(pagination.searchKeyword) || + a.UserTrueName.Contains(pagination.searchKeyword) || + a.PhoneNo.Contains(pagination.searchKeyword) || a.RoleName.Contains(pagination.searchKeyword)); } //鏃堕棿鏌ヨ if (pagination.startDate.HasValue && pagination.endDate.HasValue) { - query = query.Where((a, b) => b.CreateDate >= pagination.startDate.Value && b.CreateDate <= pagination.endDate.Value); + query = query.Where((a, b) => a.CreateDate >= pagination.startDate.Value && a.CreateDate <= pagination.endDate.Value); } //鎺掑簭 if (!string.IsNullOrEmpty(pagination.sortField)) @@ -961,38 +1019,38 @@ { - "CreateDate" => isAcs ? query.OrderBy((a, b) => b.CreateDate) : query.OrderByDescending((a, b) => b.CreateDate), + "CreateDate" => isAcs ? query.OrderBy((a, b) => a.CreateDate) : query.OrderByDescending((a, b) => a.CreateDate), - _ => query.OrderByDescending((a, b) => b.Creater) // 榛樿鎸夊垱寤烘椂闂撮檷搴� + _ => query.OrderByDescending((a, b) => a.Creater) // 榛樿鎸夊垱寤烘椂闂撮檷搴� }; } else { - query = query.OrderByDescending((a, b) => b.Creater); + query = query.OrderByDescending((a, b) => a.Creater); } var reslut = query.Select((a, b) => new { - b.User_Id, - b.UserName, - b.UserTrueName, - b.Unit, - b.Userteam, - b.Role_Id, - b.IsLeader, - //b.RoleName, - b.CardNumber, - b.PhoneNo, - b.UserPwd, - b.DeptName, - b.Dept_Id, - b.Email, - b.Enable, - b.Gender, - b.HeadImageUrl, - b.Address, - b.CreateDate, - b.Creater, + a.User_Id, + a.UserName, + a.UserTrueName, + a.Unit, + a.Userteam, + a.Role_Id, + a.IsLeader, + a.CardNumber, + a.PhoneNo, + a.UserPwd, + a.DeptName, + a.Dept_Id, + a.Email, + a.Enable, + a.Gender, + //b.UserFaceImagePath, + b.UserFaceImageName, + a.Address, + a.CreateDate, + a.Creater, a.RoleName, }).ToPageList(pagination.pageIndex, pagination.pageSize, ref totalCount); @@ -1016,8 +1074,49 @@ return new WebResponseContent { Status = false, Message = ex.Message }; } - } - + } + + + /// <summary> + /// 鎵归噺鍒犻櫎 + /// </summary> + /// <param name="keys">鐢ㄦ埛id</param> + /// <returns></returns> + public WebResponseContent DelUserList(int[] keys) + { + WebResponseContent webResponse = new WebResponseContent(); + foreach (int key in keys) + { + var user = BaseDal.QueryData(x => x.User_Id == key).FirstOrDefault(); + if (user == null) + { + return webResponse.Error("娌℃湁鎵惧埌璇ョ敤鎴�"); + } + var main = _MainServer.QueryData(x => x.UserAccount == user.UserName).FirstOrDefault(); + var face = _userFace.QueryData(x => x.UserName == user.UserName).FirstOrDefault(); + if (main.MaintenanceStatus == 1) + { + return WebResponseContent.Instance.Error("璇ョ敤鎴疯繕鍦ㄦ淇腑锛屾棤娉曞垹闄�"); + } + if (face==null) + { + BaseDal.DeleteData(user); + _MainServer.DeleteData(main); + } + else + { + BaseDal.DeleteData(user); + _MainServer.DeleteData(main); + _userFace.DeleteData(face); + } + } + + return webResponse.OK(); + } + + + + } } -- Gitblit v1.9.3