feat(identity): add server sessions and audited mail recovery

This commit is contained in:
TakuyaYagam1 committed 2026-10-07 11:03:46 +03:00
1 parent 20c03288d6
commit 4ee53d9a74
58 files changed
+5359 -567

No files matched your search

@@ -3,12 +3,16 @@ package identity
import (
"context"
"errors"
"fmt"
"lincodex/backend/internal/domain"
"lincodex/backend/internal/port/outbound"
)
//nolint:gosec // G101: this fixed value is only used for dummy Argon2 work and never authenticates an account.
const dummyLoginPassword = "lincodex-login-dummy-password"
// Credentials applies the password rules in the order that keeps hashing
// bounded: the cheap length and encoding checks first, the expensive KDF only
// for a password that passes them.
@@ -52,3 +56,18 @@ func (credentials *Credentials) VerifyLoginPassword(ctx context.Context, raw str
}
return nil
}
// VerifyDummyLoginPassword spends the same password-hash work for an unknown
// account as VerifyLoginPassword does for a known one. The result is always a
// mismatch unless the hasher fails for an operational reason.
func (credentials *Credentials) VerifyDummyLoginPassword(ctx context.Context, raw string) error {
password, err := domain.ParseLoginPassword(raw)
if err != nil {
password, _ = domain.ParseLoginPassword(dummyLoginPassword)
}
err = credentials.hasher.VerifyDummy(ctx, password)
if errors.Is(err, outbound.ErrPasswordMismatch) {
return outbound.ErrPasswordMismatch
}
return fmt.Errorf("Credentials.VerifyDummyLoginPassword - verify dummy hash: %w", err)
}