Files
tiku-backend.net/Tiku.Infrastructure/Auth/LetterAndDigitPasswordValidator.cs
xiong c497a3ca8d
Some checks failed
ci / release-gate (push) Has been cancelled
清理代码
2026-08-03 12:31:39 +08:00

24 lines
805 B
C#

using Microsoft.AspNetCore.Identity;
namespace Tiku.Infrastructure.Auth;
public sealed class LetterAndDigitPasswordValidator<TUser> : IPasswordValidator<TUser>
where TUser : class
{
public Task<IdentityResult> ValidateAsync(
UserManager<TUser> manager,
TUser user,
string? password)
{
var valid = password is { Length: >= 8 } &&
password.Any(char.IsLetter) &&
password.Any(char.IsDigit);
return Task.FromResult(valid
? IdentityResult.Success
: IdentityResult.Failed(new IdentityError
{
Code = "PasswordRequiresLetterAndDigit",
Description = "Password must be at least 8 characters and contain both letters and digits."
}));
}
}