|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
using NPin.Framework.Core.Crypt.BCrypt;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using NPin.Framework.Core.Crypt.BCrypt;
|
|
|
|
|
using NPin.Framework.SqlSugarCore.Abstractions.Data;
|
|
|
|
|
using NPin.Framework.Upms.Domain.Entities.ValueObjects;
|
|
|
|
|
using NPin.Framework.Upms.Domain.Shared.Enums;
|
|
|
|
@ -28,8 +29,8 @@ public class UserEntity : Entity<Guid>, ISoftDelete, IAuditedObject, IEnabled, I
|
|
|
|
|
[SugarColumn(ColumnDescription = "昵称")]
|
|
|
|
|
public string? Nickname { get; set; }
|
|
|
|
|
|
|
|
|
|
[SugarColumn(ColumnDescription = "密码", IsOwnsOne = true)]
|
|
|
|
|
public EncryptPasswordValueObject? EncryptPassword { get; set; } = new EncryptPasswordValueObject();
|
|
|
|
|
[SugarColumn(IsOwnsOne = true)]
|
|
|
|
|
public EncryptPasswordValueObject EncryptPassword { get; set; } = new();
|
|
|
|
|
|
|
|
|
|
[SugarColumn(ColumnDescription = "简介")]
|
|
|
|
|
public string? Introduction { get; set; }
|
|
|
|
@ -50,12 +51,12 @@ public class UserEntity : Entity<Guid>, ISoftDelete, IAuditedObject, IEnabled, I
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 逻辑删除
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool IsDeleted { get; }
|
|
|
|
|
public bool IsDeleted { get; set; }
|
|
|
|
|
|
|
|
|
|
public DateTime CreationTime { get; } = DateTime.Now;
|
|
|
|
|
public Guid? CreatorId { get; }
|
|
|
|
|
public DateTime? LastModificationTime { get; }
|
|
|
|
|
public Guid? LastModifierId { get; }
|
|
|
|
|
public DateTime CreationTime { get; set; } = DateTime.Now;
|
|
|
|
|
public Guid? CreatorId { get; set; }
|
|
|
|
|
public DateTime? LastModificationTime { get; set; }
|
|
|
|
|
public Guid? LastModifierId { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 是否启用
|
|
|
|
@ -123,10 +124,10 @@ public class UserEntity : Entity<Guid>, ISoftDelete, IAuditedObject, IEnabled, I
|
|
|
|
|
{
|
|
|
|
|
// 若传入密码无值,则使用原本Password
|
|
|
|
|
// 若原本Password依然无值,则抛出参数异常
|
|
|
|
|
password ??= EncryptPassword?.Password ?? throw new ArgumentNullException(nameof(EncryptPassword.Password));
|
|
|
|
|
|
|
|
|
|
password ??= EncryptPassword.Password ?? throw new ArgumentNullException(nameof(EncryptPassword.Password));
|
|
|
|
|
|
|
|
|
|
EncryptPassword.Salt = BCrypt.GenerateSalt();
|
|
|
|
|
EncryptPassword.Password = BCrypt.Generate(password, EncryptPassword.Salt, 0).ToString()!;
|
|
|
|
|
EncryptPassword.Password = BCrypt.GenerateStr(password, EncryptPassword.Salt, 10);
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
@ -139,11 +140,11 @@ public class UserEntity : Entity<Guid>, ISoftDelete, IAuditedObject, IEnabled, I
|
|
|
|
|
/// <exception cref="ArgumentNullException"></exception>
|
|
|
|
|
public bool CheckPassword(string password)
|
|
|
|
|
{
|
|
|
|
|
if (EncryptPassword?.Salt is null)
|
|
|
|
|
if (EncryptPassword.Salt is null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException(nameof(EncryptPassword.Salt));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return BCrypt.Check(EncryptPassword.Password, password, EncryptPassword.Salt, 0);
|
|
|
|
|
|
|
|
|
|
return BCrypt.Check(EncryptPassword.Password, password, EncryptPassword.Salt, 10);
|
|
|
|
|
}
|
|
|
|
|
}
|