Documentation
¶
Overview ¶
Package password owns credential hashing and verification: one argon2id/scrypt hash per user (PHC format via pkg/crypto), plus the identity lookup used by the sign-in flow. HTTP sign-in routes belong to the session feature.
Index ¶
- Variables
- func ValidateSecret(secret string) error
- type PostgresStore
- type Service
- func (s *Service) Name() string
- func (s *Service) SetPassword(ctx context.Context, userID user.UserID, secret string) error
- func (s *Service) VerifyForUser(ctx context.Context, userID user.UserID, secret string) error
- func (s *Service) VerifyIdentity(ctx context.Context, identityText, secret string) (user.User, error)
- type Store
Constants ¶
This section is empty.
Variables ¶
var ErrDisabled = errors.New("password: account is disabled")
ErrDisabled is returned when the account exists but is disabled.
var ErrInvalidCredentials = errors.New("password: invalid credentials")
ErrInvalidCredentials is returned for unknown identities and wrong secrets alike, so responses never reveal which one failed.
var ErrNoPassword = errors.New("password: account has no password credential")
ErrNoPassword is returned when the account has no credential row (e.g. passkey-only accounts).
var ErrOversizeSecret = errors.New("password: at most 128 characters allowed")
ErrOversizeSecret rejects secrets above the policy ceiling.
var ErrWeakPassword = errors.New("password: at least 8 characters required")
ErrWeakPassword rejects new passwords shorter than the minimum.
Functions ¶
func ValidateSecret ¶
ValidateSecret exposes the single password policy for sibling features (recovery) so the rules never live in two places.
Types ¶
type PostgresStore ¶
type PostgresStore struct {
// contains filtered or unexported fields
}
PostgresStore persists credentials in public.user_passwords.
func NewPostgresStore ¶
func NewPostgresStore(exec datastore.Executor) *PostgresStore
NewPostgresStore builds the production credential store.
func (*PostgresStore) HashByIdentity ¶
func (s *PostgresStore) HashByIdentity(ctx context.Context, identity string) (string, user.User, error)
HashByIdentity resolves a username or email to the credential hash and the owning user row, for sign-in verification.
func (*PostgresStore) HashByUserID ¶
HashByUserID returns the credential hash for a known user.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service verifies credentials and owns password lifecycle rules. Sign-in session creation happens in the session feature; this service only answers "is this secret valid".
func NewService ¶
NewService builds the credential feature on the given store and hasher. The optional recorder captures credential changes.
func (*Service) Name ¶
Name names the feature for logs. The feature is headless: its routes (sign-in, sign-out) live in the session feature.
func (*Service) SetPassword ¶
SetPassword assigns (or rotates) the credential for the user.
func (*Service) VerifyForUser ¶
VerifyForUser checks the current secret of a known user, used before sensitive operations (password change).
func (*Service) VerifyIdentity ¶
func (s *Service) VerifyIdentity(ctx context.Context, identityText, secret string) (user.User, error)
VerifyIdentity checks a username/email + secret pair and returns the account on success. Unknown identities burn the same hashing work as real ones so timing never short-circuits; disabled accounts fail closed.
type Store ¶
type Store interface {
Upsert(ctx context.Context, userID user.UserID, passwordHash string) error
HashByIdentity(ctx context.Context, identity string) (string, user.User, error)
HashByUserID(ctx context.Context, userID user.UserID) (string, error)
}
Store persists credential hashes. One row per user (user_id PK).