diff --git a/YiSha.Cache/YiSha.MemoryCache/YiSha.MemoryCache.csproj b/YiSha.Cache/YiSha.MemoryCache/YiSha.MemoryCache.csproj
index 25e99e28..ef11b459 100644
--- a/YiSha.Cache/YiSha.MemoryCache/YiSha.MemoryCache.csproj
+++ b/YiSha.Cache/YiSha.MemoryCache/YiSha.MemoryCache.csproj
@@ -5,7 +5,7 @@
-
+
diff --git a/YiSha.Util/YiSha.Util/YiSha.Util.csproj b/YiSha.Util/YiSha.Util/YiSha.Util.csproj
index 2b5cfe3f..acf91506 100644
--- a/YiSha.Util/YiSha.Util/YiSha.Util.csproj
+++ b/YiSha.Util/YiSha.Util/YiSha.Util.csproj
@@ -6,6 +6,7 @@
+
all
diff --git a/YiSha.Web/YiSha.Admin.Web/Controllers/HomeController.cs b/YiSha.Web/YiSha.Admin.Web/Controllers/HomeController.cs
index 46d34bc8..cb607625 100644
--- a/YiSha.Web/YiSha.Admin.Web/Controllers/HomeController.cs
+++ b/YiSha.Web/YiSha.Admin.Web/Controllers/HomeController.cs
@@ -17,6 +17,8 @@
using YiSha.Entity.OrganizationManage;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
+using Lazy.Captcha.Core;
+using System.IO;
namespace YiSha.Admin.Web.Controllers
{
@@ -26,6 +28,12 @@ public class HomeController : BaseController
private UserBLL userBLL = new UserBLL();
private LogLoginBLL logLoginBLL = new LogLoginBLL();
private MenuAuthorizeBLL menuAuthorizeBLL = new MenuAuthorizeBLL();
+ private readonly ICaptcha _captcha;
+
+ public HomeController(ICaptcha captcha)
+ {
+ _captcha = captcha;
+ }
#region 视图功能
[HttpGet]
@@ -129,11 +137,14 @@ public IActionResult Skin()
public IActionResult GetCaptchaImage()
{
string sessionId = GlobalContext.ServiceProvider?.GetService().HttpContext.Session.Id;
-
- Tuple captchaCode = CaptchaHelper.GetCaptchaCode();
- byte[] bytes = CaptchaHelper.CreateCaptchaImage(captchaCode.Item1);
- new SessionHelper().WriteSession("CaptchaCode", captchaCode.Item2);
- return File(bytes, @"image/jpeg");
+ //Tuple captchaCode = CaptchaHelper.GetCaptchaCode();
+ //byte[] bytes = CaptchaHelper.CreateCaptchaImage(captchaCode.Item1);
+ //new SessionHelper().WriteSession("CaptchaCode", captchaCode.Item2);
+ //return File(bytes, @"image/jpeg");
+ var info = _captcha.Generate(sessionId);
+ var stream = new MemoryStream(info.Bytes);
+ new SessionHelper().WriteSession("CaptchaCode", Convert.ToInt32(info.Code));
+ return File(stream, "image/jpeg");
}
#endregion
diff --git a/YiSha.Web/YiSha.Admin.Web/Startup.cs b/YiSha.Web/YiSha.Admin.Web/Startup.cs
index eb28b0c1..c3bf3f73 100644
--- a/YiSha.Web/YiSha.Admin.Web/Startup.cs
+++ b/YiSha.Web/YiSha.Admin.Web/Startup.cs
@@ -19,6 +19,8 @@
using YiSha.Util.Model;
using YiSha.Admin.Web.Controllers;
using Microsoft.Extensions.Logging;
+using Lazy.Captcha.Core.Generator;
+using Lazy.Captcha.Core;
namespace YiSha.Admin.Web
{
@@ -68,6 +70,25 @@ public void ConfigureServices(IServiceCollection services)
services.AddDataProtection().PersistKeysToFileSystem(new DirectoryInfo(GlobalContext.HostingEnvironment.ContentRootPath + Path.DirectorySeparatorChar + "DataProtection"));
+ //capture code
+ services.AddCaptcha(Configuration, option =>
+ {
+ option.CaptchaType = CaptchaType.ARITHMETIC; // 验证码类型
+ option.CodeLength = 2; // 验证码长度, 要放在CaptchaType设置后. 当类型为算术表达式时,长度代表操作的个数
+ option.ExpirySeconds = 60; // 验证码过期时间
+ option.IgnoreCase = true; // 比较时是否忽略大小写
+ option.StoreageKeyPrefix = ""; // 存储键前缀
+ option.ImageOption.FrameDelay = 30; // 每帧延迟,Animation=true时有效, 默认30
+
+ option.ImageOption.Width = 150; // 验证码宽度
+ option.ImageOption.Height = 50; // 验证码高度
+ //option.ImageOption.BackgroundColor = SixLabors.ImageSharp.Color.White; // 验证码背景色
+ option.ImageOption.InterferenceLineCount = 2; // 干扰线数量
+ option.ImageOption.FontSize = 36; // 字体大小
+ option.ImageOption.FontFamily = DefaultFontFamilys.Instance.Actionj; // 字体
+ option.ImageOption.TextBold = true;// 粗体,该配置2.0.3新增
+ });
+
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); // 注册Encoding
GlobalContext.SystemConfig = Configuration.GetSection("SystemConfig").Get();