密码,邮箱手机号码验证

This commit is contained in:
2021-07-08 14:22:27 +08:00
parent f5762bfade
commit bf32a1825b
8 changed files with 194 additions and 56 deletions

View File

@@ -128,7 +128,6 @@ namespace Ewide.Core.Service
/// 新密码
/// </summary>
[Required(ErrorMessage = "新密码不能为空")]
[StringLength(32, MinimumLength = 5, ErrorMessage = "密码需要大于5个字符")]
public string NewPassword { get; set; }
/// <summary>

View File

@@ -29,7 +29,7 @@ namespace Ewide.Core.Service
Task<dynamic> SendCode(Usermailphone input);
Task<dynamic> CheckBindcode(Usermailphone input);
Task<dynamic> GetPwdRule();
Task<dynamic> GetOrgUserTree(OrgUserInput input);
}
}

View File

@@ -1,6 +1,7 @@
using Ewide.Core.Service.Role;
using Ewide.Core.Service.User.Dto;
using Ewide.Core.Util;
using Furion;
using Furion.DatabaseAccessor;
using Furion.DatabaseAccessor.Extensions;
using Furion.DataEncryption;
@@ -312,11 +313,26 @@ namespace Ewide.Core.Service
public async Task UpdateUserPwd(ChangePasswordUserInput input)
{
var user = await _sysUserRep.FirstOrDefaultAsync(u => u.Id == _userManager.UserId);
if (MD5Encryption.Encrypt(input.Password) != user.Password)
throw Oops.Oh(ErrorCode.D1004);
if (MD5Encryption.Encrypt(input.NewPassword).Equals(user.Password))
var Password = RSAHandler.RSADecrypt(input.Password);
Password = MD5Encryption.Encrypt(Password);
if (Password != user.Password)
{
throw Oops.Oh("旧密码不正确");
}
var newPassword = RSAHandler.RSADecrypt(input.NewPassword);
// 验证新密码强度
var pattern = App.Configuration.GetSection("SimplePassword:Pattern").Value;
if (!Regex.Match(newPassword, pattern).Success)
{
throw Oops.Oh("新密码强度不符合规则");
}
newPassword = MD5Encryption.Encrypt(newPassword);
if (newPassword.Equals(user.Password))
throw Oops.Oh(ErrorCode.D10041);
user.Password = MD5Encryption.Encrypt(input.NewPassword);
user.Password = newPassword;
}
/// <summary>
@@ -467,7 +483,7 @@ namespace Ewide.Core.Service
var Mailcode_Key = "ewide_mailcode";
var Regex_phone = @"^((13[0-9])|(14[5,7])|(15[^4,\\D])|(17[0,1,3,6-8])|(18[0-9])|(19[8,9])|(166))[0-9]{8}$";
var Regex_Email = @"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$";
CodeHelper ch = new CodeHelper(_iMemoryCache);
CodeHelper ch = new CodeHelper(_iMemoryCache, _sysUserRep, _userManager);
//Type为1时给原手机号发送验证码
if (input.Type == 1)
{
@@ -484,7 +500,7 @@ namespace Ewide.Core.Service
//Type为2时给原邮箱发送验证码
else if (input.Type == 2)
{
if (new Regex(@"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$").IsMatch(_userManager.User.Email))
if (new Regex(Regex_Email).IsMatch(_userManager.User.Email))
{
try
{
@@ -500,6 +516,7 @@ namespace Ewide.Core.Service
//Type为null时则发验证码
else
{
await ch.CheckRepeat(input.Target);
//通过正则判断绑定类型
if (new Regex(Regex_phone).IsMatch(input.Target))
{
@@ -542,7 +559,7 @@ namespace Ewide.Core.Service
var Regex_phone = @"^((13[0-9])|(14[5,7])|(15[^4,\\D])|(17[0,1,3,6-8])|(18[0-9])|(19[8,9])|(166))[0-9]{8}$";
var Regex_Email = @"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$";
var user = await _sysUserRep.FirstOrDefaultAsync(u => u.Id == _userManager.UserId);
CodeHelper ch = new CodeHelper(_iMemoryCache);
CodeHelper ch = new CodeHelper(_iMemoryCache, _sysUserRep,_userManager);
if (input.Type == 1)
{
if (ch.Checkcode(_userManager.User.Phone, input.Orgcode, Orgcode_Key))
@@ -655,6 +672,23 @@ namespace Ewide.Core.Service
}
}
/// <summary>
/// 获取密码强度配置
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/sysUser/getPwdRule")]
public async Task<dynamic> GetPwdRule()
{
return new LoginOutput
{
Pattern = App.Configuration.GetSection("SimplePassword:Pattern").Value,
Descriptions = App.Configuration.GetSection("SimplePassword:Descriptions").Value
};
}
[HttpPost("/sysUser/GetOrgUserTree")]
public async Task<dynamic> GetOrgUserTree(OrgUserInput input)
{