feat(identity): hash passwords with Argon2id and bounded inputs

This commit is contained in:
shira committed 2026-10-06 01:07:55 +03:00
1 parent 6153887eb5
commit dda3825786
26 files changed
+1475 -32

No files matched your search

+13 -1
View File
@@ -945,6 +945,17 @@ func TestIdentityRepositories(t *testing.T) {
statement: `UPDATE users SET password_hash = 'correct horse battery staple' WHERE id = $1`,
args: []any{user.ID},
},
{
// The domain regex rejects zero and leading-zero parameters too.
constraint: "users_password_hash_format",
statement: `UPDATE users SET password_hash = '$argon2id$v=19$m=0,t=2,p=1$c2FsdHNhbHRzYWx0$aGFzaGhhc2hoYXNoaGFzaGhhc2hoYXNoaGFzaA' WHERE id = $1`,
args: []any{user.ID},
},
{
constraint: "users_password_hash_format",
statement: `UPDATE users SET password_hash = '$argon2id$v=19$m=019456,t=2,p=1$c2FsdHNhbHRzYWx0$aGFzaGhhc2hoYXNoaGFzaGhhc2hoYXNoaGFzaA' WHERE id = $1`,
args: []any{user.ID},
},
{
// The key matches the address, so only the ASCII rule fails.
constraint: "users_email_ascii",
@@ -1111,7 +1122,8 @@ func assertSameUser(t *testing.T, got, want domain.User) {
t.Helper()
sameVerification := (got.EmailVerifiedAt == nil) == (want.EmailVerifiedAt == nil) &&
(got.EmailVerifiedAt == nil || got.EmailVerifiedAt.Equal(*want.EmailVerifiedAt))
if got.ID != want.ID || got.Email != want.Email || got.PasswordHash.PHC() != want.PasswordHash.PHC() ||
if got.ID != want.ID || got.Email.Address() != want.Email.Address() || got.Email.Normalized() != want.Email.Normalized() ||
got.PasswordHash.PHC() != want.PasswordHash.PHC() ||
got.Scenario != want.Scenario || got.OnboardingStep != want.OnboardingStep || !sameVerification ||
got.RegistrationVersion != want.RegistrationVersion || !got.LastRegisteredAt.Equal(want.LastRegisteredAt) ||
got.Version != want.Version || !got.CreatedAt.Equal(want.CreatedAt) || !got.UpdatedAt.Equal(want.UpdatedAt) {