package password import "testing" // TestPasswordHash 验证 Argon2id 密码哈希的校验行为。 // // 入参: // - `t` 表示当前测试上下文。 // // 返回: // - 无返回值。 func TestPasswordHash(t *testing.T) { const ( salt = "0123456789abcdef" password = "safe-password" ) newHash := Hash(salt, password) // 来自迁移前实现的固定公开输入向量,不能因迁移重算账号哈希。 const legacy = "$argon2id$v=19$m=65536,t=3,p=2$bZYOvJXmIZjZB9pB8SfHP3+tg56rWnDsjzTHsc3NcAM" if newHash != legacy { t.Fatal("legacy hash format changed") } if !Verify(salt, password, newHash) { t.Fatal("Argon2id 密码应校验成功") } if Verify(salt, "wrong-password", newHash) { t.Fatal("错误密码不应校验成功") } if Verify(salt, password, "6f7a5ccfa9d4e28f") { t.Fatal("非 Argon2id 密码摘要不应校验成功") } }