diff --git a/04.系统编码/App/Controllers/UserController.cs b/04.系统编码/App/Controllers/UserController.cs index 485dd4f..d7e13ee 100644 --- a/04.系统编码/App/Controllers/UserController.cs +++ b/04.系统编码/App/Controllers/UserController.cs @@ -3,6 +3,7 @@ using System.Web.Mvc; using Pingchuan.BeijingSafeguard.BLL; using Pingchuan.BeijingSafeguard.Model; +using Pingchuan.BeijingSafeguard.Utility; namespace Pingchuan.BeijingSafeguard.App.Controllers { @@ -16,7 +17,7 @@ namespace Pingchuan.BeijingSafeguard.App.Controllers [HttpPost] public JsonResult Login(string name, string password) { - User user = UserBLL.GetUser(name ,password); + User user = UserBLL.GetUser(name, Helper.CalcMD5(password)); if (user != null) { SetLoginUser(user); diff --git a/04.系统编码/App/Controllers/UserManagementController.cs b/04.系统编码/App/Controllers/UserManagementController.cs index 81e5879..490d588 100644 --- a/04.系统编码/App/Controllers/UserManagementController.cs +++ b/04.系统编码/App/Controllers/UserManagementController.cs @@ -3,6 +3,7 @@ using System.Web.Mvc; using Pingchuan.BeijingSafeguard.BLL; using Pingchuan.BeijingSafeguard.Model; +using Pingchuan.BeijingSafeguard.Utility; namespace Pingchuan.BeijingSafeguard.App.Controllers { @@ -17,6 +18,7 @@ namespace Pingchuan.BeijingSafeguard.App.Controllers [HttpPost] public JsonResult Add(User user) { + user.LoginPassword = Helper.CalcMD5(user.LoginPassword); int id = UserBLL.Add(user); return Json(id); } diff --git a/04.系统编码/Model/User.cs b/04.系统编码/Model/User.cs index c323a6f..0823558 100644 --- a/04.系统编码/Model/User.cs +++ b/04.系统编码/Model/User.cs @@ -29,7 +29,7 @@ namespace Pingchuan.BeijingSafeguard.Model public string LoginName { set; get; } [Column("login_password")] - public string LoginPassWord { set; get; } + public string LoginPassword { set; get; } [Column("compute_count")] public int ComputeCount { get; set; } diff --git a/04.系统编码/Utility/Helper.cs b/04.系统编码/Utility/Helper.cs new file mode 100644 index 0000000..fe396f4 --- /dev/null +++ b/04.系统编码/Utility/Helper.cs @@ -0,0 +1,26 @@ +using System; +using System.Text; +using System.Security.Cryptography; + +namespace Pingchuan.BeijingSafeguard.Utility +{ + public class Helper + { + public static string CalcMD5(string input) + { + // Use input string to calculate MD5 hash + using (MD5 md5 = MD5.Create()) + { + byte[] inputBytes = Encoding.ASCII.GetBytes(input); + byte[] hashBytes = md5.ComputeHash(inputBytes); + + // Convert the byte array to hexadecimal string + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < hashBytes.Length; i++) + sb.Append(hashBytes[i].ToString("x2")); + + return sb.ToString(); + } + } + } +} \ No newline at end of file diff --git a/04.系统编码/Utility/Utility.csproj b/04.系统编码/Utility/Utility.csproj index bc35d36..300778a 100644 --- a/04.系统编码/Utility/Utility.csproj +++ b/04.系统编码/Utility/Utility.csproj @@ -42,6 +42,7 @@ +