From d1770d5326f9ee90c74a723734a74b953da2e11f Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sun, 1 Mar 2020 12:41:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=A2=E6=88=B7=E7=AB=AF=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E5=A2=9E=E5=8A=A0=E5=8A=A0=E5=AF=86=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Api/EncrptyController.cs | 50 +++++++++++++++++++ .../Controllers/ToolsController.cs | 14 ++++-- .../Bootstrap.Client/Models/EncrptyModel.cs | 18 +++++++ .../Views/Tools/Encrpty.cshtml | 38 ++++++++++++++ .../Bootstrap.Client/wwwroot/js/encrpty.js | 25 ++++++++++ 5 files changed, 142 insertions(+), 3 deletions(-) create mode 100644 src/client/Bootstrap.Client/Controllers/Api/EncrptyController.cs create mode 100644 src/client/Bootstrap.Client/Models/EncrptyModel.cs create mode 100644 src/client/Bootstrap.Client/Views/Tools/Encrpty.cshtml create mode 100644 src/client/Bootstrap.Client/wwwroot/js/encrpty.js 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