diff --git a/src/client/Bootstrap.Client/Controllers/Api/EncrptyController.cs b/src/client/Bootstrap.Client/Controllers/Api/EncrptyController.cs new file mode 100644 index 00000000..3b7b0ec7 --- /dev/null +++ b/src/client/Bootstrap.Client/Controllers/Api/EncrptyController.cs @@ -0,0 +1,50 @@ +using Longbow.Security.Cryptography; +using Microsoft.AspNetCore.Mvc; + +namespace Bootstrap.Client.Controllers.Api +{ + /// + /// 运维邮件发送接口 + /// + [Route("api/[controller]/[action]")] + [ApiController] + public class EncrptyController : ControllerBase + { + /// + /// 生成加密盐值方法 + /// + /// + [HttpGet] + public IActionResult Salt() + { + return new JsonResult(LgbCryptography.GenerateSalt()); + } + + /// + /// 根据提供的原始密码与盐值计算 Hash 值 + /// + /// + /// + [HttpPost] + public IActionResult Hash([FromBody]EncrptyPostData data) + { + return new JsonResult(LgbCryptography.ComputeHash(data.Password, data.Salt)); + } + } + + /// + /// 加密数据提交类 + /// + public class EncrptyPostData + { + /// + /// 获得/设置 加密盐值 + /// + public string Salt { get; set; } = ""; + + /// + /// 获得/设置 要加密的原始密码 + /// + public string Password { get; set; } = ""; + } +} diff --git a/src/client/Bootstrap.Client/Controllers/ToolsController.cs b/src/client/Bootstrap.Client/Controllers/ToolsController.cs index 03fd2ec2..c60406c8 100644 --- a/src/client/Bootstrap.Client/Controllers/ToolsController.cs +++ b/src/client/Bootstrap.Client/Controllers/ToolsController.cs @@ -11,14 +11,13 @@ namespace Bootstrap.Client /// /// Tools 控制器 /// - [Authorize] + [Authorize(Roles = "Administrators")] public class ToolsController : Controller { /// /// SQL 视图 /// /// - [Authorize(Roles = "Administrators")] [HttpGet] public IActionResult SQL() { @@ -29,7 +28,6 @@ namespace Bootstrap.Client /// SQL 视图 /// /// - [Authorize(Roles = "Administrators")] [HttpGet] public IActionResult Mail() { @@ -100,5 +98,15 @@ namespace Bootstrap.Client return db.Execute(sql); } } + + /// + /// 加密工具控制器 + /// + /// + [HttpGet] + public IActionResult Encrpty() + { + return View(new EncrptyModel(this)); + } } } diff --git a/src/client/Bootstrap.Client/Models/EncrptyModel.cs b/src/client/Bootstrap.Client/Models/EncrptyModel.cs new file mode 100644 index 00000000..b9c1ac13 --- /dev/null +++ b/src/client/Bootstrap.Client/Models/EncrptyModel.cs @@ -0,0 +1,18 @@ +using Microsoft.AspNetCore.Mvc; + +namespace Bootstrap.Client.Models +{ + /// + /// Encrpty Model + /// + public class EncrptyModel : NavigatorBarModel + { + /// + /// 构造函数 + /// + public EncrptyModel(ControllerBase controller) : base(controller) + { + + } + } +} diff --git a/src/client/Bootstrap.Client/Views/Tools/Encrpty.cshtml b/src/client/Bootstrap.Client/Views/Tools/Encrpty.cshtml new file mode 100644 index 00000000..ff491731 --- /dev/null +++ b/src/client/Bootstrap.Client/Views/Tools/Encrpty.cshtml @@ -0,0 +1,38 @@ +@model EncrptyModel +@{ + ViewData["Title"] = "加密工具类"; +} +@section javascript { + +} +
+
加密工具
+
+
+
+
+ + +
+
+ +
+ +
+ +
+
+
+
+ +
+ +
+ +
+
+
+
+
+
+
diff --git a/src/client/Bootstrap.Client/wwwroot/js/encrpty.js b/src/client/Bootstrap.Client/wwwroot/js/encrpty.js new file mode 100644 index 00000000..ab90f879 --- /dev/null +++ b/src/client/Bootstrap.Client/wwwroot/js/encrpty.js @@ -0,0 +1,25 @@ +$(function () { + $(document).on('click', '[data-method]', function (e) { + var method = $(this).attr('data-method'); + switch (method) { + case 'salt': + $.bc({ + url: 'api/Encrpty/Salt', method: 'get', callback: function (result) { + $('#salt').val(result); + } + }); + break; + case 'hash': + $.bc({ + url: 'api/Encrpty/Hash', method: 'post', data: { password: $('#password').val(), salt: $('#salt').val() }, callback: function (result) { + $('#hash').val(result); + } + }); + break; + default: + break; + } + }); + + $.footer(); +}); \ No newline at end of file