Documentation
¶
Index ¶
- Constants
- Variables
- func HashPassword(plaintext string) (string, error)
- func ThrottleKey(encryptionKeyHex string) ([]byte, error)
- func ValidatePassword(plaintext string) error
- func VerifyPassword(hash, plaintext string) error
- type AuditRecorder
- type AuditTxWriter
- type ConfirmResetReq
- type EmailSender
- type Handler
- type LoginInput
- type LoginReq
- type LoginResponse
- type LoginResult
- type LoginThrottle
- func (t *LoginThrottle) Cleanup(ctx context.Context) (int, error)
- func (t *LoginThrottle) InboxProved(w http.ResponseWriter, r *http.Request, email string) error
- func (t *LoginThrottle) Reserve(r *http.Request, email string) (ThrottleVerdict, error)
- func (t *LoginThrottle) SignedIn(w http.ResponseWriter, r *http.Request, email string, v ThrottleVerdict) error
- type PostgresStore
- func (s *PostgresStore) AttachTenantInTx(ctx context.Context, tx *sql.Tx, userID, tenantID, role string) error
- func (s *PostgresStore) CheckJoin(ctx context.Context, u domain.User, tenantID string) error
- func (s *PostgresStore) CreateInTx(ctx context.Context, tx *sql.Tx, email, passwordHash, tenantID, role string) (domain.User, error)
- func (s *PostgresStore) CreateResetToken(ctx context.Context, userID, tokenHash string, expiresAt time.Time) (domain.PasswordResetToken, error)
- func (s *PostgresStore) GetByEmail(ctx context.Context, email string) (domain.User, error)
- func (s *PostgresStore) GetByID(ctx context.Context, id string) (domain.User, error)
- func (s *PostgresStore) LookupResetToken(ctx context.Context, tokenHash string) (string, error)
- func (s *PostgresStore) ResetPassword(ctx context.Context, tokenHash, passwordHash string, ...) (domain.User, error)
- func (s *PostgresStore) SignIn(ctx context.Context, userID, verifiedHash string, at time.Time, ...) (string, error)
- func (s *PostgresStore) TenantsForUser(ctx context.Context, userID string) ([]domain.UserTenant, error)
- type RequestResetReq
- type Service
- func (s *Service) CheckResetToken(ctx context.Context, plaintext string) error
- func (s *Service) ConfirmReset(ctx context.Context, plaintext, newPassword string) (domain.User, error)
- func (s *Service) GetByID(ctx context.Context, id string) (domain.User, error)
- func (s *Service) IssueResetToken(ctx context.Context, email string) (plaintext, tenantID, userID string, err error)
- func (s *Service) Login(ctx context.Context, in LoginInput) (LoginResult, error)
- func (s *Service) Logout(ctx context.Context, rawSessionCookie string) (session.Session, bool, error)
- func (s *Service) SetMode(ctx context.Context, rawSessionCookie string, livemode bool) (session.Session, bool, error)
- type SessionWriter
- type SetModeReq
- type Store
- type ThrottleVerdict
Constants ¶
const ( // MinPasswordLength is the only complexity rule we enforce. NIST // SP 800-63B recommends against required-character classes (they // reduce real-world security by encouraging predictable // substitutions). 12 chars is the post-2024 floor for low-stakes // systems; we'd raise to 16 for a financial-services tenant if a // DP requested. MinPasswordLength = 12 // PasswordResetTokenTTL is how long a reset token remains valid. // 1 hour matches the GitHub / AWS Cognito / Auth0 default — long // enough for the recipient to find the email and click, short // enough that a leaked token isn't useful days later. PasswordResetTokenTTL = 1 * time.Hour )
const ( // ResetSendsPerWindow / ResetSendWindow bound how many reset EMAILS one // account can be sent. The per-IP limiter on /v1/auth slows credential // stuffing but does nothing against one caller pointing many requests at // a single victim's address, each inside the IP budget — flooding their // inbox and burning SMTP quota. // // The budget is derived from password_reset_tokens itself: the rows ARE // the record of what was sent, so the cap is cluster-wide by // construction, survives restarts, and needs no Redis. It replaced a // Redis bucket (ha-14 PR-B) that silently vanished wherever Redis was // unreachable — verified 2026-08-31: 8 consecutive sends, 0 refusals — // and before that an in-process map that degraded to 3xN per hour at N // replicas. Keyed on the ACCOUNT rather than the typed string, so it // counts what was actually delivered. ResetSendsPerWindow = 3 ResetSendWindow = time.Hour )
const ( // DeviceCookieName is the cookie that marks a browser that signed in. // It holds 32 random bytes as hex and is sent only to /v1/auth. DeviceCookieName = "hardcount_device" )
The sign-in throttle (ADR-094, amended 2026-10-18). It slows repeated wrong passwords instead of locking the account.
Every sign-in attempt is counted before the password is checked, under one or two subjects:
- A browser that has signed in to this email before (it sends the hardcount_device cookie) is counted under that browser and email only. Guesses from elsewhere never hold it out.
- Any other browser is counted twice: under its address and the email, which stops one source early; and under the email alone, which caps guesses spread over many addresses.
Once a subject reaches its threshold, each further attempt starts a wait: 1 minute, then 2, 4 and 8, then 15 minutes per attempt. An attempt made during a wait is refused before any account lookup or bcrypt, and is not counted. A count whose last attempt is over 24 hours old starts again. Proof of the account (the right password, a completed password reset, an accepted invite) marks the browser and clears this address's count. Only the right password from a browser the email's count held clears that count too (SignedIn says why).
Every subject is an HMAC keyed from HARDCOUNT_ENCRYPTION_KEY, and the typed email is used as typed (trimmed, lower-cased), so an email with no account is counted and answered exactly like a real one. All times come from the database clock, so every copy of the server shares one count.
Variables ¶
var ErrBadCredentials = errors.New("invalid email or password")
ErrBadCredentials covers both "no such user" and "wrong password". Same error for both so an attacker can't enumerate registered emails by timing the response. Handler maps to 401.
var ErrEmailTaken = errs.AlreadyExists("email", "an account with this email already exists")
ErrEmailTaken is returned when CreateInTx hits the email unique violation. Surfaced to the API as 409.
var ErrResetSendCapped = errors.New("user: password-reset send cap reached for this account")
Store is the persistence boundary for user accounts, the user↔tenant join, and password reset tokens. ADR-011. ErrResetSendCapped means this account has already been sent ResetSendsPerWindow reset links inside ResetSendWindow, so no token was issued. It is not an error the caller surfaces: the endpoint's response is fixed either way (the fixed body is the account-enumeration defence).
Functions ¶
func HashPassword ¶
HashPassword applies bcrypt to a candidate plaintext. Validates length and the breached-password list before hashing. Returns the hash suitable for `users.password_hash`.
func ThrottleKey ¶
ThrottleKey derives the throttle's HMAC key from HARDCOUNT_ENCRYPTION_KEY (64 hex characters) with HKDF. With no key, as in local development, it derives from a fixed value: the subjects then still hold no email or address, but anyone with the code can test a guess against them. Production refuses to start without a key.
func ValidatePassword ¶
ValidatePassword runs the password rules without hashing. HashPassword calls it.
func VerifyPassword ¶
VerifyPassword does a constant-time bcrypt compare. Returns nil on match, a generic ErrBadCredentials on mismatch (no leaking of "user exists vs password wrong"), or a wrapped error on implementation failures.
Types ¶
type AuditRecorder ¶
type AuditRecorder interface {
Log(ctx context.Context, tenantID, action, resourceType, resourceID, resourceLabel string, metadata map[string]any) error
}
AuditRecorder writes the audit row of the password-reset request. A nil recorder leaves that request with no row, which the unit tests that build a bare handler rely on.
type AuditTxWriter ¶ added in v0.10.0
AuditTxWriter writes an audit row on the caller's transaction. *audit.Logger satisfies it.
type ConfirmResetReq ¶
type EmailSender ¶
type EmailSender interface {
SendPasswordReset(ctx context.Context, tenantID, email, resetLink string) error
}
EmailSender is the narrow surface this handler uses to dispatch password-reset emails. Satisfied in production by an adapter over internal/email's Sender / OutboxSender. SMTP misconfiguration surfaces as a SendPasswordReset error logged here; the response to the user stays generic to prevent enumeration.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler wires the dashboard auth endpoints. ADR-011.
Routes (mounted under /v1/auth):
POST /login email + password → mint cookie POST /logout end the session, clear the cookie POST /mode switch the session's mode POST /password-reset/request email → send reset link POST /password-reset/confirm token + new password → set
func NewHandler ¶
func NewHandler(users *Service, cookie session.CookieConfig, emailSender EmailSender, dashboardBaseURL string, smtpConfigured bool) *Handler
NewHandler wires the dependencies. emailSender is required — password-reset requests will nil-panic if it's nil. dashboardBaseURL is the canonical dashboard origin used to build password-reset links; it is never derived from the request (Host header) to prevent host-header poisoning / token theft. When empty, password-reset emails are not sent (requestPasswordReset fails safe). Set it to your dashboard URL — in split-origin dev (Vite on :5173 vs API on :8080) that's the SPA URL.
func (*Handler) Routes ¶
Routes returns the dashboard auth surface. Mount under /v1/auth. All routes are intentionally outside session middleware: they're either pre-session (login, password-reset) or take the cookie via r.Cookie directly (logout, mode).
func (*Handler) SetAuditLogger ¶
func (h *Handler) SetAuditLogger(a AuditRecorder)
SetAuditLogger wires the recorder for the password-reset request. A sign-in, a sign-out, a mode switch and a completed reset write their row on their own transaction (Service.Login, Logout, SetMode, ConfirmReset). A failed sign-in writes no row: it has no workspace to file one under, and a row would say the address exists. It goes to the security log.
func (*Handler) SetLoginThrottle ¶
func (h *Handler) SetLoginThrottle(t *LoginThrottle)
SetLoginThrottle wires the sign-in throttle (throttle.go). Production always wires it in internal/api; the e2e tests there prove it. A handler without one checks every password, as before the throttle.
type LoginInput ¶ added in v0.10.0
type LoginInput struct {
Email string
Password string
UserAgent string
IP string
// SessionCookie is the raw value of the session cookie the request
// carried, or "" when it carried none. That session ends when the
// sign-in commits, because the new cookie replaces it in the browser.
SessionCookie string
}
LoginInput is what a sign-in needs: the typed email and password, and the request's user agent, client address and session cookie.
type LoginResponse ¶
type LoginResponse struct {
UserID string `json:"user_id"`
TenantID string `json:"tenant_id"`
Email string `json:"email"`
Livemode bool `json:"livemode"`
ExpiresAt string `json:"expires_at"`
}
LoginResponse is POST /v1/auth/login's 200.
type LoginResult ¶ added in v0.10.0
type LoginResult struct {
User domain.User
TenantID string
RawSessionID string
Session session.Session
}
LoginResult is a committed sign-in: the user, the workspace the session is in, the raw session id for the cookie and the session.
type LoginThrottle ¶
type LoginThrottle struct {
// contains filtered or unexported fields
}
LoginThrottle counts sign-in attempts in the login_throttle table.
func NewLoginThrottle ¶
func NewLoginThrottle(db *postgres.DB, key []byte, cookie session.CookieConfig) *LoginThrottle
NewLoginThrottle builds the throttle. key comes from ThrottleKey; cookie gives the hardcount_device cookie the session cookie's Domain and Secure.
func (*LoginThrottle) Cleanup ¶
func (t *LoginThrottle) Cleanup(ctx context.Context) (int, error)
Cleanup deletes rows nothing reads any more: no attempt for 24 hours, no wait still running, and no sign-in from that browser within 180 days. The leader runs it with the other cleanup steps.
func (*LoginThrottle) InboxProved ¶
func (t *LoginThrottle) InboxProved(w http.ResponseWriter, r *http.Request, email string) error
InboxProved records a completed password reset or an accepted invite. Each proves the inbox, so it marks the browser and clears this address's count for the email, like a sign-in. It leaves the email's count running: the marked browser is no longer held by it, and clearing it would end other people's wait early (see SignedIn).
func (*LoginThrottle) Reserve ¶
func (t *LoginThrottle) Reserve(r *http.Request, email string) (ThrottleVerdict, error)
Reserve counts one sign-in attempt for the typed email from this request, before the password is checked. When any of the attempt's subjects is in a wait, nothing is counted and the verdict is a refusal.
func (*LoginThrottle) SignedIn ¶
func (t *LoginThrottle) SignedIn(w http.ResponseWriter, r *http.Request, email string, v ThrottleVerdict) error
SignedIn records a sign-in with the right password. v is the verdict Reserve gave the same request. The sign-in marks the browser, sets the hardcount_device cookie and clears this address's count for the email.
It clears the email's count only when the attempt was counted under it, that is, from a browser that never signed in to the email. A successful sign-in should reset the failures it was held by (NIST SP 800-63B-4 §3.2.2), and without that reset a person who signs in from private windows, or a script with no cookie jar, would pile up waits. Such a sign-in cannot end a running wait: during one, the attempt was refused. A known browser was never held by the email's count, so its sign-in leaves the count alone. Clearing it there would end other people's wait early, which shows a guesser that the email has an account and gives them a new allowance of guesses.
type PostgresStore ¶
type PostgresStore struct {
// contains filtered or unexported fields
}
PostgresStore is the production persistence for user accounts. All queries run under TxBypass — there is no tenant context for users (a user *belongs to* tenants via user_tenants but the user row itself is global). Auth resolution happens before any tenant ctx is available.
func NewPostgresStore ¶
func NewPostgresStore(db *postgres.DB) *PostgresStore
func (*PostgresStore) AttachTenantInTx ¶ added in v0.10.0
func (s *PostgresStore) AttachTenantInTx(ctx context.Context, tx *sql.Tx, userID, tenantID, role string) error
AttachTenantInTx adds the user to tenantID with role on the caller's transaction, which must be a bypass one, and does not commit. It locks the user's row first, so two accepts of one account run one after the other. A member of any other workspace is refused (memberElsewhere), even one who is also a member of tenantID. A member of tenantID alone is left as they are.
func (*PostgresStore) CheckJoin ¶ added in v0.10.0
CheckJoin returns the refusal AttachTenantInTx would give u for tenantID, and nil otherwise. It takes no lock, so the accept checks again.
func (*PostgresStore) CreateInTx ¶
func (s *PostgresStore) CreateInTx(ctx context.Context, tx *sql.Tx, email, passwordHash, tenantID, role string) (domain.User, error)
CreateInTx inserts a user and their tenant attachment inside the CALLER's transaction — the seam tenant.RunBootstrap needs so the owner user commits (or rolls back) atomically with the tenant, keys, and settings it belongs to (ADR-073). The invite accept uses it too, so a new account commits with the invitation's claim. passwordHash must already be a bcrypt hash (user.HashPassword validates + hashes). No commit here; the caller owns the tx.
func (*PostgresStore) CreateResetToken ¶
func (s *PostgresStore) CreateResetToken(ctx context.Context, userID, tokenHash string, expiresAt time.Time) (domain.PasswordResetToken, error)
func (*PostgresStore) GetByEmail ¶
func (*PostgresStore) LookupResetToken ¶
LookupResetToken returns the user id of a reset link that can still be used: the token is unused and unexpired, and its user belongs to a workspace. That is the rule ResetPassword applies, without spending the token. Returns errs.ErrNotFound otherwise.
func (*PostgresStore) ResetPassword ¶ added in v0.10.0
func (s *PostgresStore) ResetPassword(ctx context.Context, tokenHash, passwordHash string, then func(tx *sql.Tx, userID string) error) (domain.User, error)
ResetPassword redeems a reset token and sets the user's password hash in one bypass transaction. In order, it spends the token, voids the user's other unused tokens, writes passwordHash, finds the user's first-joined workspace (the one login picks), stamps app.tenant_id with it and app.livemode off for an audit row, and calls then. then runs last, on the same transaction, with the token's owner. It must not commit or roll back tx; an error it returns rolls the whole reset back and is returned.
It returns errResetLinkDead, and changes nothing, when the token is unknown, expired or used, or when the user belongs to no workspace: such a user cannot sign in, and an audit row has no tenant to go to.
func (*PostgresStore) SignIn ¶ added in v0.10.0
func (s *PostgresStore) SignIn(ctx context.Context, userID, verifiedHash string, at time.Time, then func(tx *sql.Tx, tenantID string) error) (string, error)
SignIn records a sign-in in one bypass transaction. In order, it locks the user's row and checks that its password hash is still verifiedHash, reads the user's first-joined workspace (the order TenantsForUser uses) with a lock on that membership row, writes at as last_login_at, stamps app.tenant_id with the workspace and app.livemode off for an audit row, and calls then. then runs last, on the same transaction, with the workspace. It must not commit or roll back tx; an error it returns rolls the whole sign-in back and is returned.
It returns errPasswordChanged when the hash is no longer verifiedHash or the user's row is gone, and errNoWorkspace when the user belongs to no workspace, and changes nothing in both cases.
The row locks are what keep the sign-in true when it commits. A password reset updates the user's row, so the lock waits for a reset in flight and the check then sees its new hash. A member removal deletes the membership row and ends the member's sessions in its own transaction. Either the lock waits for the removal, and the read then finds the user's next membership (a user with one workspace has none and gets errNoWorkspace; a user with more signs in to the next one), or the removal waits for this commit and its sign-out ends the session this sign-in created.
FOR UPDATE, not FOR SHARE, on the user's row: this transaction updates the row, and two sign-ins of one user that each held a share lock would deadlock on that update. FOR KEY SHARE on the membership row: it conflicts with the removal's delete, and not with another sign-in or an update that leaves the row's key alone, so sign-ins of one workspace's members do not queue behind each other.
func (*PostgresStore) TenantsForUser ¶
func (s *PostgresStore) TenantsForUser(ctx context.Context, userID string) ([]domain.UserTenant, error)
type RequestResetReq ¶
type RequestResetReq struct {
Email string `json:"email"`
}
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the auth-side surface for user accounts. ADR-011.
The recipe is intentionally boring: bcrypt cost 12 for hashing, crypto/rand for tokens, sha256 for token storage. The sign-in throttle (throttle.go, ADR-094) runs in the handler before Login. All of this is well-trodden Go stdlib + x/crypto territory.
func NewService ¶
func NewService(store Store, clk clock.Clock, sessions SessionWriter, auditor AuditTxWriter) *Service
NewService returns a Service. sessions and auditor write on the sign-in's and the password reset's transactions. For a sign-out and a mode switch, sessions owns the transaction and calls a hook that writes the audit row.
func (*Service) CheckResetToken ¶
CheckResetToken returns nil when the reset link can still be used: the token is unused and unexpired, and its user belongs to a workspace, the same rule ConfirmReset applies. Otherwise it returns the token error. It spends nothing; the reset-password page calls it before it shows the form, and ConfirmReset calls it before the slow hash.
func (*Service) ConfirmReset ¶ added in v0.10.0
func (s *Service) ConfirmReset(ctx context.Context, plaintext, newPassword string) (domain.User, error)
ConfirmReset sets newPassword for the user whose reset token is plaintext, and returns that user. It checks the link first and answers a dead link with the token error before any bcrypt work, so a dead link sent with a bad password gets the token error. It then checks and hashes the password outside any transaction: a refused password spends nothing, and bcrypt holds no row lock. One transaction then spends the token, voids the user's other tokens, sets the hash, ends every session of the user and writes the password_reset_completed audit row, so either all of it happens or none of it does. A link used up between the check and the transaction still gets the token error.
func (*Service) GetByID ¶
GetByID looks up a user by id. Used by /v1/whoami to project email onto the cookie-path response without forcing the session row to duplicate it.
func (*Service) IssueResetToken ¶
func (s *Service) IssueResetToken(ctx context.Context, email string) (plaintext, tenantID, userID string, err error)
IssueResetToken generates a fresh reset token for the user with the given email, persists the hash, and returns the plaintext (caller emails it to the user via the reset link) along with the user's tenant_id (caller threads it into the email-outbox row so the password-reset email lands on the right tenant for operator visibility). Returns ("", "", nil) if the email doesn't match — the caller should always render the same "if your email is on file, you'll get a link" response so we don't leak account existence. IssueResetToken also returns the matched user's ID so the caller can record an audit row that POINTS AT the account instead of STORING its email. audit_log is append-only (0150 revoked DELETE), so an address written into a row is an erasure dead end; a user id is not.
func (*Service) Login ¶ added in v0.10.0
func (s *Service) Login(ctx context.Context, in LoginInput) (LoginResult, error)
Login verifies email and password and signs the user in to their first-joined workspace. It returns ErrBadCredentials for a missing user or a wrong password: the same error, with the same timing on both paths (the not-found path runs a dummy bcrypt), so response timing cannot be used to enumerate registered emails.
The account read and the bcrypt run outside any transaction, so bcrypt holds no row lock. One transaction (PostgresStore.SignIn) then first checks that the password is still the one verified and finds the user's first-joined workspace, and after those checks stamps last_login_at, ends the session the request's cookie named, creates the new session and writes the login audit row, so either all of it happens or none of it does. A password changed while the sign-in ran gets ErrBadCredentials; a user with no workspace gets errs.InvalidState, a 409.
There is no account-lock check, and there never is: the sign-in throttle (throttle.go) slows guesses before this runs and does not lock an account (ADR-094). An account under active attack is handled by password reset / session revocation, not by refusing login.
func (*Service) Logout ¶ added in v0.10.0
func (s *Service) Logout(ctx context.Context, rawSessionCookie string) (session.Session, bool, error)
Logout ends the session rawSessionCookie names and writes the logout audit row on the same transaction, so both happen or neither does. It returns the ended session and whether a live session was found; when none was (no cookie value, an unknown, ended or expired session), nothing is written. The row is filed in test mode, as every account event is.
func (*Service) SetMode ¶ added in v0.10.0
func (s *Service) SetMode(ctx context.Context, rawSessionCookie string, livemode bool) (session.Session, bool, error)
SetMode switches the session rawSessionCookie names to livemode and writes the mode_changed audit row on the same transaction, so both happen or neither does. It returns the session in its new mode and whether a live session was found; when none was, nothing changes. The row is filed in test mode whatever the new mode, as every account event is, and records the new mode in its metadata.
type SessionWriter ¶ added in v0.10.0
type SessionWriter interface {
IssueTx(ctx context.Context, tx *sql.Tx, in session.IssueInput) (rawID string, sess session.Session, err error)
EndTx(ctx context.Context, tx *sql.Tx, rawID string) (ended bool, err error)
EndAllForUserTx(ctx context.Context, tx *sql.Tx, userID string) error
End(ctx context.Context, rawID string, then func(tx *sql.Tx, sess session.Session) error) (session.Session, bool, error)
SetLivemode(ctx context.Context, rawID string, livemode bool, then func(tx *sql.Tx, sess session.Session) error) (session.Session, bool, error)
}
SessionWriter changes sessions. The Tx methods write on the caller's transaction. End and SetLivemode open their own transaction and run a hook on it. *session.Service satisfies it.
type SetModeReq ¶
type SetModeReq struct {
Livemode *bool `json:"livemode"`
}
SetModeReq is POST /v1/auth/mode's body. Livemode is required: a pointer, so a body without it is told apart from false.
type Store ¶
type Store interface {
// GetByEmail loads the user with the given email (case-insensitive
// via citext). Returns errs.ErrNotFound when no row matches.
GetByEmail(ctx context.Context, email string) (domain.User, error)
// GetByID loads the user by id.
GetByID(ctx context.Context, id string) (domain.User, error)
// SignIn locks the user's row, checks that its password hash is still
// verifiedHash, locks the user's first-joined membership, writes at as
// last_login_at and stamps the transaction for an audit row in that
// workspace. then runs last, on the same transaction, with the
// workspace. It must not commit or roll back tx; an error it returns
// rolls the whole sign-in back and is returned. Returns
// errPasswordChanged when the hash is no longer verifiedHash, and
// errNoWorkspace when the user belongs to no workspace, and changes
// nothing in both cases.
SignIn(ctx context.Context, userID, verifiedHash string, at time.Time, then func(tx *sql.Tx, tenantID string) error) (tenantID string, err error)
// TenantsForUser returns the tenant memberships for a user. v1 has
// 1:1 user:tenant; the shape supports growth.
TenantsForUser(ctx context.Context, userID string) ([]domain.UserTenant, error)
// CreateResetToken enforces the per-account send cap and inserts a row
// whose token_hash matches the caller-provided hash. Plaintext token
// never enters the DB. Over the cap it returns ErrResetSendCapped and
// writes nothing; the caller sends no email and answers with the same
// fixed generic body.
CreateResetToken(ctx context.Context, userID, tokenHash string, expiresAt time.Time) (domain.PasswordResetToken, error)
// ResetPassword spends the token whose hash is tokenHash, voids the
// user's other tokens, sets passwordHash and stamps the transaction for
// an audit row in the user's first-joined workspace. then runs last, on
// the same transaction, with the token's owner. It must not commit or
// roll back tx; an error it returns rolls the whole reset back and is
// returned. Returns errResetLinkDead, and changes nothing, for a token
// that is unknown, expired or used, or a user with no workspace.
ResetPassword(ctx context.Context, tokenHash, passwordHash string, then func(tx *sql.Tx, userID string) error) (domain.User, error)
// LookupResetToken returns the owning user_id when ResetPassword would
// accept the token: unused, unexpired, and its user belongs to a
// workspace. It changes nothing. Returns errs.ErrNotFound otherwise.
LookupResetToken(ctx context.Context, tokenHash string) (string, error)
}
type ThrottleVerdict ¶
type ThrottleVerdict struct {
Allowed bool
RetryAfter time.Duration // when refused: until the longest wait ends
// Account is the first 12 hex characters of the email's subject. Logs
// use it to group attempts on one email from any address without
// writing the email down.
Account string
// contains filtered or unexported fields
}
ThrottleVerdict says whether one sign-in attempt may go on to the password check.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package breachedpw holds the breached-password list that user.ValidatePassword checks when a password is set or reset (ADR-095, "Offline breached-password").
|
Package breachedpw holds the breached-password list that user.ValidatePassword checks when a password is set or reset (ADR-095, "Offline breached-password"). |
|
gen
command
Command gen rebuilds internal/user/breachedpw/passwords.txt from a downloaded copy of the source list.
|
Command gen rebuilds internal/user/breachedpw/passwords.txt from a downloaded copy of the source list. |