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

22 lines
700 B
C#

using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Options;
using Tiku.Domain.Identity;
namespace Tiku.IntegrationTests.Api;
internal static class PasswordTestUserExtensions
{
public const string TestPassword = "passw0rd!123";
public static User WithTestPassword(this User user)
{
user.UserName ??= user.Phone ?? user.Email ?? user.Id.ToString("N");
user.NormalizedUserName ??= user.UserName.ToUpperInvariant();
var hasher = new PasswordHasher<User>(Options.Create(new PasswordHasherOptions
{
IterationCount = 210_000
}));
user.PasswordHash = hasher.HashPassword(user, TestPassword);
return user;
}
}