优化登录验证码设置

This commit is contained in:
不做码农 2022-10-11 21:45:15 +08:00
parent 33136d5bdd
commit a7219048f5
2 changed files with 24 additions and 6 deletions

View File

@ -155,7 +155,24 @@ namespace ZR.Admin.WebApi.Controllers.System
SysConfig sysConfig = sysConfigService.GetSysConfigByKey("sys.account.captchaOnOff");
var captchaOff = sysConfig?.ConfigValue ?? "0";
var code = SecurityCodeHelper.GetRandomEnDigitalText(4);
var length = AppSettings.GetAppConfig<int>("CaptchaOptions:length", 4);
var code = SecurityCodeHelper.GetRandomEnDigitalText(length);
byte[] imgByte = GenerateCaptcha(captchaOff, code);
string base64Str = Convert.ToBase64String(imgByte);
CacheHelper.SetCache(uuid, code);
var obj = new { uuid, img = base64Str };// File(stream, "image/png")
return ToJson(1, obj);
}
/// <summary>
/// 生成图片验证码
/// </summary>
/// <param name="captchaOff"></param>
/// <param name="code"></param>
/// <returns></returns>
private byte[] GenerateCaptcha(string captchaOff, string code)
{
byte[] imgByte;
if (captchaOff == "1")
{
@ -173,11 +190,8 @@ namespace ZR.Admin.WebApi.Controllers.System
{
imgByte = SecurityCodeHelper.GetEnDigitalCodeByte(code);//英文字母加数字
}
string base64Str = Convert.ToBase64String(imgByte);
CacheHelper.SetCache(uuid, code);
var obj = new { uuid, img = base64Str };// File(stream, "image/png")
return ToJson(1, obj);
return imgByte;
}
/// <summary>

View File

@ -24,7 +24,7 @@
"uploadUrl": "http://localhost:8888", //访
"localSavePath": "uploads", // wwwroot/uploads
"maxSize": 15, // 15M
"notAllowedExt": [ ".bat", ".exe", ".jar", ".js"]
"notAllowedExt": [ ".bat", ".exe", ".jar", ".js" ]
},
//
"ALIYUN_OSS": {
@ -105,5 +105,9 @@
"IpRules": [
]
}
},
//
"CaptchaOptions": {
"length": 4
}
}