兼容现有 PBKDF2 密码和 hz_session Cookie TOTP 绑定、二步登录、防重放、恢复码与 AES-GCM 密钥 与 Node 完全一致的 Redis 键格式,可跨运行时共享会话 生产环境开启原生认证时强制要求 Redis 默认保持兼容代理;设置 AUTH_NATIVE_ENABLED=true 即可切换
30 lines
963 B
C#
30 lines
963 B
C#
using Eis.Infrastructure.Authentication;
|
|
|
|
namespace Eis.Infrastructure.Tests.Authentication;
|
|
|
|
public sealed class PasswordCompatibilityServiceTests
|
|
{
|
|
[Fact]
|
|
public void VerifiesNodePbkdf2PasswordHash()
|
|
{
|
|
const string stored = "00112233445566778899aabbccddeeff:7a69c21675902559aa0cae041a3b4ebb3bc1402bb70a753eff44f5b32543c270";
|
|
var service = new PasswordCompatibilityService();
|
|
|
|
Assert.True(service.Verify("兼容Password123!", stored));
|
|
Assert.False(service.Verify("wrong-password", stored));
|
|
}
|
|
|
|
[Fact]
|
|
public void CreatesHashUsingLegacySaltAndDigestShape()
|
|
{
|
|
var service = new PasswordCompatibilityService();
|
|
var stored = service.Hash("Password123!");
|
|
var parts = stored.Split(':');
|
|
|
|
Assert.Equal(2, parts.Length);
|
|
Assert.Equal(32, parts[0].Length);
|
|
Assert.Equal(64, parts[1].Length);
|
|
Assert.True(service.Verify("Password123!", stored));
|
|
}
|
|
}
|