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

+23 -6
View File
@@ -38,8 +38,15 @@ var ErrInvalidEmailAddress = errors.New("invalid email address")
// the domain, a rule for Unicode local parts, and SMTPUTF8 delivery.
//
// String, GoString, Format, and LogValue redact the address so it does not
// reach logs by accident; Address returns the real value.
// reach logs by accident; Address returns the real value. Both forms sit
// behind a pointer: fmt cannot call Format on an unexported field of an
// enclosing struct and prints its contents instead, but for a pointer it
// prints only the address. A nil pointer is the zero, invalid value.
type EmailAddress struct {
value *emailAddressValue
}
type emailAddressValue struct {
address string
normalized string
}
@@ -69,7 +76,7 @@ func NewEmailAddress(raw string) (EmailAddress, error) {
if err := validateEmailDomain(domainPart); err != nil {
return EmailAddress{}, err
}
return EmailAddress{address: address, normalized: normalizeEmailKey(address)}, nil
return EmailAddress{value: &emailAddressValue{address: address, normalized: normalizeEmailKey(address)}}, nil
}
// RestoreEmailAddress rebuilds an EmailAddress from storage. It checks only
@@ -79,7 +86,7 @@ func RestoreEmailAddress(address, normalized string) (EmailAddress, error) {
if address == "" || normalized != normalizeEmailKey(address) {
return EmailAddress{}, fmt.Errorf("domain.RestoreEmailAddress - stored key does not match the stored address: %w", ErrInvalidEmailAddress)
}
return EmailAddress{address: address, normalized: normalized}, nil
return EmailAddress{value: &emailAddressValue{address: address, normalized: normalized}}, nil
}
// normalizeEmailKey lowercases A-Z only, independent of locale and Unicode
@@ -139,13 +146,23 @@ func invalidEmailAddress(reason string) error {
// Address returns the delivery form. Use it only where the address is needed:
// storage, mail delivery, and the account view.
func (email EmailAddress) Address() string { return email.address }
func (email EmailAddress) Address() string {
if email.value == nil {
return ""
}
return email.value.address
}
// Normalized returns the comparison key that storage keeps unique.
func (email EmailAddress) Normalized() string { return email.normalized }
func (email EmailAddress) Normalized() string {
if email.value == nil {
return ""
}
return email.value.normalized
}
// IsZero reports an EmailAddress not built by NewEmailAddress.
func (email EmailAddress) IsZero() bool { return email.normalized == "" }
func (email EmailAddress) IsZero() bool { return email.value == nil }
func (email EmailAddress) String() string { return redactedEmailAddress }