Documentation
¶
Overview ¶
Package password signs humans in with an email address and a password, held to OWASP ASVS 5.0.0: Level 2 in full, and Level 3 where the library can own the requirement.
A password is the weakest factor. Alone it is single-factor, and it counts as a fresh factor only while it is the strongest factor the account has: see auth.MethodPassword. A code sent by email confirms an address or resets a password; it is never a factor and never starts a session.
Passwords are hashed with Argon2id, at or above the OWASP Password Storage Cheat Sheet's minimum, and stored as PHC strings that carry their parameters. With Config.AcceptBcrypt, the package also verifies bcrypt hashes imported from another product, and replaces each with Argon2id on the first correct password; it never creates one.
The policy follows NIST SP 800-63B-4: a minimum of 15 characters by default, a maximum of 256, no composition rules, no expiry, a list of 10,000 common passwords, context words that don't count, and an optional breached-password check in the pwned subpackage. Nothing locks an account: failed attempts only slow later attempts down.
The library still owns no users. The application creates an account in a hook, as it does for a federated sign-up, and sends the mail that the library asks for.
Index ¶
- Constants
- Variables
- func CheckHash(hash string, acceptBcrypt bool) error
- func IsBcrypt(hash string) bool
- func NormalizeEmail(address string) (key string, err error)
- type AddInput
- type Added
- type BreachChecker
- type BreachOutage
- type ChangeOptions
- type Changed
- type Config
- type Confirmation
- type Confirmer
- type ContextFunc
- type ForgotOptions
- type Links
- type Mailer
- type MailerFunc
- type Message
- type MessageKind
- type NewUser
- type NewUserFunc
- type Params
- type Passwords
- func (p *Passwords) Add(ctx context.Context, who auth.Principal, in AddInput) (Added, error)
- func (p *Passwords) Change(ctx context.Context, who auth.Principal, current, next string, o ChangeOptions) (Changed, error)
- func (p *Passwords) ChangeEmail(ctx context.Context, who auth.Principal, address string) error
- func (p *Passwords) Confirm(ctx context.Context, code string, by Confirmer) (Confirmation, error)
- func (p *Passwords) ConfirmTTL() time.Duration
- func (p *Passwords) Forgot(ctx context.Context, address string, o ForgotOptions) error
- func (p *Passwords) Remove(ctx context.Context, who auth.Principal, o RemoveOptions) (Changed, error)
- func (p *Passwords) ResendVerification(ctx context.Context, who auth.Principal) error
- func (p *Passwords) Reset(ctx context.Context, code, next string, o ResetOptions) (auth.UserID, error)
- func (p *Passwords) ResetTTL() time.Duration
- func (p *Passwords) SignIn(ctx context.Context, address, password string, o SignInOptions) (SignedIn, error)
- func (p *Passwords) SignUp(ctx context.Context, in SignUpInput) error
- func (p *Passwords) StartReset(ctx context.Context, u auth.UserID, o StartResetOptions) error
- func (p *Passwords) Status(ctx context.Context, u auth.UserID) (Status, error)
- func (p *Passwords) Verify(ctx context.Context, who auth.Principal, password string) (auth.Proof, error)
- type PolicyError
- type RemoveOptions
- type ResetOptions
- type Secret
- type SignInOptions
- type SignUpInput
- type SignedIn
- type StartResetOptions
- type Status
- type Store
- type Verification
Constants ¶
const ( MinBcryptCost = 10 MaxBcryptCost = 14 )
Bounds on a stored bcrypt hash. A cost outside them is never computed, so a tampered row can't hold a CPU for minutes.
const ( RuleTooShort = "too_short" RuleTooLong = "too_long" RuleCommon = "common" RuleContext = "context" RuleBreached = "breached" RuleNotText = "not_text" )
Rules that a PolicyError names.
const ( CodeTooShort auth.ProblemCode = "password_too_short" CodeTooLong auth.ProblemCode = "password_too_long" CodeCommon auth.ProblemCode = "password_common" CodeContext auth.ProblemCode = "password_context" CodeBreached auth.ProblemCode = "password_breached" CodeInvalid auth.ProblemCode = "password_invalid" )
Problem codes of a PolicyError.
const ( DefaultConfirmTTL = 24 * time.Hour MaxConfirmTTL = emailcode.MaxTTL DefaultResetTTL = emailcode.MaxProofTTL MaxResetTTL = emailcode.MaxProofTTL )
Defaults and limits of the code lifetimes.
const ( ActionSignUp = "password.sign_up" ActionConfirm = "password.confirm" ActionSignIn = "password.sign_in" ActionVerify = "password.verify" ActionChange = "password.change" ActionForgot = "password.forgot" ActionReset = "password.reset" ActionAdd = "password.add" ActionChangeEmail = "password.change_email" ActionResend = "password.resend" )
Limiter actions.
const ( KindVerify = "password.verify" KindSignUp = "password.sign_up" KindAdd = "password.add" KindChangeEmail = "password.change_email" )
Kinds of the codes that Passwords.Confirm redeems, in Confirmation.Kind.
const ( DefaultMinLength = 15 DefaultMaxLength = 256 )
Bounds on the policy's lengths, in characters.
const CodePasswordWrong auth.ProblemCode = "password_wrong"
CodePasswordWrong is the hint for a wrong password after the person is identified, from Verify and Change.
const FreshFor = 10 * time.Minute
FreshFor is how recent a session's proof must be to change a password or an address.
NeverShare is the warning every email with a typed code shows next to the code.
Variables ¶
var ( ErrTooShort = errors.New("password: too short") ErrTooLong = errors.New("password: too long") ErrCommon = errors.New("password: too common") ErrContext = errors.New("password: too close to the account's own words") ErrBreached = errors.New("password: found in a data breach") ErrNotText = errors.New("password: not valid UTF-8") )
Errors that a password can fail the policy with. A *PolicyError matches the one for its rule.
var ( // ErrCodeInvalid means a code from a message is malformed, unknown, // used, expired, or no longer applies. ErrCodeInvalid = auth.NewError("password: invalid code", auth.Problem{ Status: 401, Code: "code_invalid", Title: "That link or code doesn't work", Fix: "A link or code works once, until it expires. Type a code in the tab where you started, or ask for another email.", }) // ErrSignInToConfirm means a code needs the account's session or // password, or the browser that signed up, before it confirms // anything. The code is kept. ErrSignInToConfirm = auth.NewError("password: sign in to confirm", auth.Problem{ Status: 401, Code: "confirm_sign_in", Title: "Sign in to confirm", Fix: "Sign in, or enter your password, in this browser, then open the link again.", }) // ErrLastSignInMethod means removing the password would leave the // account without a way to sign in. ErrLastSignInMethod = auth.NewError("password: the last sign-in method", auth.Problem{ Status: 409, Code: "last_sign_in_method", Title: "Add another way to sign in first", Fix: "Add a passkey or link a sign-in provider, then remove the password.", }) // ErrNoPassword means the account has no usable password. ErrNoPassword = auth.NewError("password: the account has no password", auth.Problem{ Status: 409, Code: "no_password", Title: "This account has no password", Fix: "Sign in another way, or add a password.", }) // ErrNoVerifiedEmail means the account has no confirmed address. ErrNoVerifiedEmail = auth.NewError("password: no confirmed email address", auth.Problem{ Status: 409, Code: "no_verified_email", Title: "No confirmed email address", Fix: "Confirm an email address for the account first.", }) )
Errors of the flows after the policy. Each has a problem for clients.
var ( NeedChange = auth.Need{Action: "password.change", Assurance: auth.AssuranceSingle, Within: FreshFor, Human: true, HoldAfterRecovery: true} NeedAdd = auth.Need{Action: "password.add", Assurance: auth.AssuranceSingle, Within: FreshFor, Human: true, HoldAfterRecovery: true} NeedRemove = auth.Need{Action: "password.remove", Assurance: auth.AssuranceSingle, Within: FreshFor, Human: true} NeedChangeEmail = auth.Need{Action: "password.change_email", Assurance: auth.AssuranceSingle, Within: FreshFor, Human: true, HoldAfterRecovery: true} NeedResend = auth.Need{Action: "password.resend", Assurance: auth.AssuranceRecovering, Human: true} )
Needs of the package's operations. auth.WithNeeds tightens them by Action.
var ErrConfig = errors.New("password: invalid configuration")
ErrConfig means New was given a configuration it refuses. Its message names the field and the fix. It is a setup error, with no problem for clients: log it and stop the server, and never pass it to auth.Describe, which turns it into a bare internal error.
var ErrEmailInvalid = auth.NewError("password: invalid email address", auth.Problem{
Status: 400, Code: "email_invalid", Title: "Check the email address",
Fix: "Enter one address, such as name@example.com, without a name or spaces.",
})
ErrEmailInvalid means an address isn't one the library accepts: see NormalizeEmail.
Functions ¶
func CheckHash ¶
CheckHash reports whether hash is a password hash that Passwords verifies: an Argon2id PHC string within the limits, or, when acceptBcrypt is set, a bcrypt hash with a cost from 10 to 14. An import calls it before storing a hash. It computes nothing.
func IsBcrypt ¶
IsBcrypt reports whether hash has a bcrypt prefix, so it is replaced with Argon2id on the first correct sign-in.
func NormalizeEmail ¶
NormalizeEmail returns the key that decides which addresses are the same account, or ErrEmailInvalid:
- It trims leading and trailing white space.
- It refuses an address that isn't valid UTF-8, is longer than 254 bytes, or contains white space, a control character, or any of "(),:;<>[\]. It splits at the last "@": the local part must be 1 to 64 bytes, and the domain 1 to 253 bytes with at least one dot and no empty label. Display names, quoted local parts, and comments are refused, so an address can't inject a mail header or a second recipient. Invisible format characters, such as zero-width spaces and direction overrides, are refused too.
- The key is the address in NFKC, lowercased, then in NFKC again. A key that wouldn't normalize to itself is refused.
It applies no provider rules, such as removing dots or "+" tags, and doesn't convert internationalized domains to ASCII: both would join addresses that some providers deliver to different people.
Types ¶
type AddInput ¶
type AddInput struct {
// Address is required when the account has no verified address.
Address string
Password string
}
AddInput is a password to add to an account.
type Added ¶
type Added struct {
// Set is true when the password works now. When it is false, the
// address must be confirmed by email first.
Set bool `json:"set"`
}
Added is the result of Add.
type BreachChecker ¶
BreachChecker reports whether a password appears in known breaches. The pwned subpackage provides one.
type BreachOutage ¶
type BreachOutage uint8
BreachOutage says what to do when the breached-password check fails.
const ( // AcceptOnOutage accepts the password and logs a warning. It is the // zero value. AcceptOnOutage BreachOutage = iota // RefuseOnOutage returns a server error. RefuseOnOutage )
type ChangeOptions ¶
type ChangeOptions struct {
// EndOtherSessions ends every other human session, personal access
// token, and OAuth grant of the account.
EndOtherSessions bool
}
ChangeOptions changes a password change.
type Changed ¶
type Changed struct {
// SessionsEnded counts the other sessions ended.
SessionsEnded int `json:"sessions_ended"`
}
Changed is the result of a change.
type Config ¶
type Config struct {
// Mailer sends the messages. It is required.
Mailer Mailer
// NewUser creates accounts. When it is nil, sign-up is closed.
NewUser NewUserFunc
// Verification is VerifyFirst, the default, or VerifyLater.
Verification Verification
// MinLength is the shortest password, in characters: 15 by default,
// and never less than 8.
MinLength int
// MaxLength is the longest password, in characters: 256 by default,
// from 64 to 1,024.
MaxLength int
// ContextWords don't count toward MinLength, for example the
// service's name. The address and its local part never count either.
ContextWords []string
// Context returns more such words for one person.
Context ContextFunc
// Breached, when set, refuses passwords it reports. It makes a
// network call for each password set.
Breached BreachChecker
// BreachOutage is AcceptOnOutage, the default, or RefuseOnOutage.
BreachOutage BreachOutage
// Params are the Argon2id parameters; zero means DefaultParams.
Params Params
// AcceptBcrypt verifies bcrypt hashes imported from another product,
// with a cost from 10 to 14, and replaces each with Argon2id on the
// first correct password. It is off by default; with it off, a stored
// bcrypt hash is a server error and is never computed. The library
// never creates a bcrypt hash.
AcceptBcrypt bool
// MaxHashes is how many Argon2 or bcrypt computations run at once, so
// memory use stays at most MaxHashes × Params.Memory. The default is
// GOMAXPROCS, and at least 2.
MaxHashes int
// ConfirmTTL is how long a code that confirms an address works: for a
// sign-up, an added password, an address change, and a verify message.
// It is 24 hours by default, from 1 minute to 72 hours. Confirming an
// address never starts a session or returns a proof, so it can outlive
// the 10-minute limit on authentication codes.
ConfirmTTL time.Duration
// ResetTTL is how long a password reset code works: 10 minutes by
// default, from 1 to 10 minutes. A reset proves possession of the
// mailbox to set a credential, so ASVS 6.5.5 caps it at 10 minutes.
ResetTTL time.Duration
// Links, when set, puts a link to the application's page in every
// message that carries a code, as Message.Link.
Links Links
}
Config configures New.
type Confirmation ¶
type Confirmation struct {
// Kind is KindVerify, KindSignUp, KindAdd, or KindChangeEmail.
Kind string `json:"kind"`
User auth.UserID `json:"user"`
Address string `json:"address"`
// Created is true when the NewUser hook created the account in this
// call.
Created bool `json:"created"`
}
Confirmation is what Passwords.Confirm did.
type Confirmer ¶
type Confirmer struct {
// Principal is the session of the request, or zero.
Principal auth.Principal
// Binding is the browser binding of the request, or empty.
Binding string
// Password is the password typed on the confirmation page, or empty.
Password string
}
Confirmer is who presents a code to Passwords.Confirm.
type ContextFunc ¶
ContextFunc returns more words that don't count toward a password's minimum length for one person, for example their name. u is empty at sign-up.
type ForgotOptions ¶
type ForgotOptions struct {
// Binding ties the reset's typed code to this browser, for example a
// random value in a cookie. Pass the same value in
// ResetOptions.Binding.
Binding string
// KnownDevice is the known-device token this browser presented, from
// SignedIn.Device. The reset message carries a typed code only when
// it is valid for the account and its current password version, and
// Binding is set: otherwise an attacker could ask for a reset of
// someone else's address from their own browser and talk the owner
// into reading the code out. Every other reset message carries the
// link only, which works on any device.
KnownDevice string
}
ForgotOptions changes how a reset can finish.
type Links ¶
type Links struct {
// Confirm opens codes that confirm an address.
Confirm string
// Reset opens password reset codes.
Reset string
}
Links are the pages that open the links in messages. Each is an absolute http or https URL without a fragment; the library appends "#code=" and the link code, so browsers never send the code to a server or in Referer. The page must change nothing when it loads: it shows a button that posts the code. authroutes serves such pages.
type Mailer ¶
Mailer sends the messages the package asks for. The library sends no mail itself.
Send must return without waiting for delivery, for example by queuing the message: every flow before identification calls it exactly once, so a mailer that blocks on one kind of message reveals which path ran. An error never changes the answer the caller gets; the library logs it.
type MailerFunc ¶
MailerFunc adapts a function to a Mailer.
type Message ¶
type Message struct {
Kind MessageKind
// To is the address as the person entered it.
To string
// User is the account, or empty when To has no account.
User auth.UserID
// Link is Config.Links' page with the link code in its fragment, or
// zero for a notice or without Config.Links.
Link Secret
// Token is the link code, or zero for a notice. Without Config.Links,
// build the link from it: put it in the URL fragment, for example
// https://app.example/confirm#code=…, so browsers don't send it to
// servers or in Referer.
Token Secret
// Code is the typed code, formatted as ABCD-EFGH, or zero for a notice,
// for a reset that a browser the account doesn't trust asked for, and
// for a reset an administrator started. It works only on the device that started the
// flow, and dies after 5 wrong guesses.
Code Secret
// ExpiresAt is when Link, Token, and Code stop working.
ExpiresAt time.Time
// Other is the other address of an address change.
Other string
// contains filtered or unexported fields
}
Message is one message to send. A message that carries a code carries it twice: as a link, for the person who opens the mail on any device, and as a typed code, for the person who types it on the device that started the flow. A good email shows the typed code in large type, says how long both work in plain words (Message.ValidFor), says what the code does (Message.CodePurpose) and NeverShare next to it, and then gives the link. A reset message carries a typed code only when a browser the account already trusts asked for it.
func (Message) CodePurpose ¶
CodePurpose says what the message's typed code does, in plain words, for example "This code resets your password." Show it, with NeverShare, next to the code. It is empty for a message without a typed code.
type MessageKind ¶
type MessageKind string
MessageKind says which message to send.
const ( // MessageVerify carries a code that confirms the account's address. MessageVerify MessageKind = "verify" // MessageConfirmSignUp carries a code that confirms a sign-up's // address before the account exists. MessageConfirmSignUp MessageKind = "confirm_sign_up" // MessageAccountExists tells the verified holder that someone signed // up with their address. MessageAccountExists MessageKind = "account_exists" // MessageSignUpClosed tells the address that sign-up is closed. MessageSignUpClosed MessageKind = "sign_up_closed" // MessageReset carries a code that resets the password. MessageReset MessageKind = "reset" // MessageResetUnverified tells an unconfirmed address that it can't // reset a password. MessageResetUnverified MessageKind = "reset_unverified" // MessageResetNoPassword tells a verified address that its account has // no password. MessageResetNoPassword MessageKind = "reset_no_password" // MessageNoAccount tells an address that it has no account. MessageNoAccount MessageKind = "no_account" // MessageConfirmAdd carries a code that confirms an address for a new // password. MessageConfirmAdd MessageKind = "confirm_add" // MessageConfirmChange carries a code that confirms a new address. MessageConfirmChange MessageKind = "confirm_change" // MessageAddressInUse tells the verified holder that another account // named their address. MessageAddressInUse MessageKind = "address_in_use" // MessageChangeRequested tells the old verified address that a change // to Other was requested. MessageChangeRequested MessageKind = "change_requested" // MessageEmailChanged tells the old verified address that the address // changed to Other. MessageEmailChanged MessageKind = "email_changed" // MessagePasswordChanged, MessagePasswordResetDone, // MessagePasswordAdded, and MessagePasswordRemoved tell the verified // address that the change happened. MessagePasswordChanged MessageKind = "password_changed" MessagePasswordResetDone MessageKind = "password_reset_done" MessagePasswordAdded MessageKind = "password_added" MessagePasswordRemoved MessageKind = "password_removed" )
Message kinds. Notices carry no code. MessageNoAccount, MessageSignUpClosed, and MessageAddressInUse go to an address without an account in that flow; an application may drop them, in the same time.
type NewUser ¶
type NewUser struct {
// Address is the address as the person entered it.
Address string
// Key is the normalized address.
Key string
// Verified is true when the mailbox is confirmed already.
Verified bool
// State is SignUpInput.State.
State []byte
}
NewUser describes a sign-up for NewUserFunc.
type NewUserFunc ¶
NewUserFunc creates the account for a sign-up and returns its user. It has the contract of federation.SignUpFunc: return only an account created in this call, never an existing one, and return an empty user to refuse, for example without an invitation.
type Params ¶
type Params struct {
// Memory is in KiB.
Memory uint32
// Time is the number of iterations.
Time uint32
// Threads is the degree of parallelism.
Threads uint8
}
Params are the Argon2id parameters for new hashes. Every hash stores its parameters, so changing Params leaves existing hashes working, and a sign-in with other parameters rehashes the password.
func DefaultParams ¶
func DefaultParams() Params
DefaultParams returns 19,456 KiB of memory, 2 iterations, and 1 thread: the configuration that the OWASP Password Storage Cheat Sheet names as its minimum for Argon2id.
type Passwords ¶
type Passwords struct {
// contains filtered or unexported fields
}
Passwords signs people in with an email address and a password. It is safe for concurrent use.
func New ¶
New returns a Passwords. It returns ErrConfig for a nil service, store, or mailer; for settings outside their ranges; for Params below the OWASP minimum; for a service without a limiter, because password guessing must be throttled; and for DevMailer on a service without auth.WithDevTools.
func (*Passwords) Add ¶
Add adds a password to who's account. It requires NeedAdd and returns auth.ErrFactorExists when the account has a password. When the account has a verified address, the password works at once and Added.Set is true. Otherwise Add needs AddInput.Address, and sends a confirm_add code to it, as ChangeEmail does; the password works once Passwords.Confirm redeems the code in a session of the account.
func (*Passwords) Change ¶
func (p *Passwords) Change(ctx context.Context, who auth.Principal, current, next string, o ChangeOptions) (Changed, error)
Change changes who's password, after checking the current one. It requires NeedChange and a new password that passes the policy. A wrong current password returns auth.HintFactor with the code password_wrong. A concurrent change returns auth.ErrConflict.
func (*Passwords) ChangeEmail ¶
ChangeEmail asks to change who's address. It requires NeedChangeEmail and returns nil for every well-formed address. The account keeps its address until the new one is confirmed with Passwords.Confirm. A free address, or one held unverified, gets a confirm_change code; an address that another account holds verified gets an address_in_use notice. A verified old address gets change_requested.
func (*Passwords) Confirm ¶
Confirm redeems a code from a verify, confirm_sign_up, confirm_add, or confirm_change message: the link code, or the typed code. A code alone never confirms anything: the caller must also be the party that holds the account's session or password, or, for a sign-up, the browser that signed up or the password it chose. Otherwise an attacker could sign up with someone else's address and wait for its owner to open the link. A typed code works only on the device that started the flow, which proves that by itself.
When the caller shows none of what the code's kind needs, Confirm returns ErrSignInToConfirm and keeps the code. A wrong password spends the code. Every other failure is ErrCodeInvalid. Confirm never returns a proof and never starts a session.
func (*Passwords) ConfirmTTL ¶
ConfirmTTL returns how long a code that confirms an address works.
func (*Passwords) Forgot ¶
Forgot sends a reset code to address when it is a verified address of an account with a password, and a notice otherwise. It returns nil for every address, or auth.ErrThrottled. Every path does one read, writes one ceremony, and sends one message; a malformed address gets nothing.
func (*Passwords) Remove ¶
func (p *Passwords) Remove(ctx context.Context, who auth.Principal, o RemoveOptions) (Changed, error)
Remove deletes who's password and keeps the address. It requires NeedRemove and returns ErrLastSignInMethod unless the account has a passkey or, when the store is an auth.IdentityStore, a linked identity.
func (*Passwords) ResendVerification ¶
ResendVerification issues a fresh verify code for who's address, and does nothing for a verified address or an account without one.
func (*Passwords) Reset ¶
func (p *Passwords) Reset(ctx context.Context, code, next string, o ResetOptions) (auth.UserID, error)
Reset sets a new password with a code from a reset message, ends every session, and returns the user. It starts no session: the person signs in with the new password, and sign-in still requires TOTP when the account has it. A password that fails the policy keeps the code, so the person can choose again. A code issued before any password change, or for an address the account no longer holds verified, is ErrCodeInvalid.
func (*Passwords) SignIn ¶
func (p *Passwords) SignIn(ctx context.Context, address, password string, o SignInOptions) (SignedIn, error)
SignIn checks address and password and returns a proof with auth.MethodPassword. Every failure returns auth.ErrFactorRejected and does the same work: one store read and one Argon2 verification, for a known address, an unknown one, an address without a password, and a malformed input. A bcrypt hash that Config.AcceptBcrypt lets through is the one exception: it costs up to 2 bcrypt computations instead. The client limit runs first, then the read, then the limit for the address.
func (*Passwords) SignUp ¶
func (p *Passwords) SignUp(ctx context.Context, in SignUpInput) error
SignUp starts a sign-up. It returns nil for every address, or an error that depends only on the input: a *PolicyError, ErrEmailInvalid, or auth.ErrThrottled. The address owner learns what happened by email. Every path does one Argon2 hash, one read, one ceremony write, and sends one message:
- A free address with VerifyFirst, and an address held unverified, get a confirm_sign_up code; Confirm creates the account.
- A free address with VerifyLater creates the account at once, with an unverified address, and gets a verify code.
- An address held verified gets an account_exists notice.
- With a nil NewUser hook, or one that refuses, the address gets a sign_up_closed notice.
func (*Passwords) StartReset ¶
StartReset sends a reset message to u's verified address, for an administrator. The administrator never sees the code and never chooses the password. With Invalidate, it first makes the current password stop working and ends every session, for a suspected compromise. It records the request with the actor from auth.WithActor. It returns ErrNoVerifiedEmail when u has no verified address and ErrNoPassword when u has no password. The application authorizes the caller, for example with an authadmin route.
func (*Passwords) Verify ¶
func (p *Passwords) Verify(ctx context.Context, who auth.Principal, password string) (auth.Proof, error)
Verify checks the password of who's user and returns a proof for auth.Service.StepUp or auth.Service.Elevate, which refuse it for an account with a passkey or confirmed TOTP. A wrong password returns auth.HintFactor with the code password_wrong, because the person is identified; an account without a usable password returns ErrNoPassword.
type PolicyError ¶
type PolicyError struct {
// Rule is RuleTooShort, RuleTooLong, RuleCommon, RuleContext,
// RuleBreached, or RuleNotText.
Rule string
// MinLength and MaxLength are the policy's bounds, in characters.
MinLength int
MaxLength int
}
PolicyError says why a new password was refused, as NIST SP 800-63B-4 requires, so the person can choose another.
func (*PolicyError) Error ¶
func (e *PolicyError) Error() string
func (*PolicyError) Is ¶
func (e *PolicyError) Is(target error) bool
Is matches the sentinel for e's rule.
func (*PolicyError) Problem ¶
func (e *PolicyError) Problem() auth.Problem
Problem describes the refusal for a client: status 400, the rule's code, and a fix that names the rule and the lengths.
type RemoveOptions ¶
type RemoveOptions struct {
// EndOtherSessions is as for ChangeOptions.
EndOtherSessions bool
}
RemoveOptions changes a password removal.
type ResetOptions ¶
type ResetOptions struct {
// KeepTokens keeps personal access tokens and OAuth grants, and ends
// only human sessions, with the agent sessions delegated from them.
// Show it unchecked.
KeepTokens bool
// Binding is ForgotOptions.Binding of the browser that asked for the
// reset. A typed code works only with it; a link code needs none.
Binding string
}
ResetOptions changes what a reset ends. The zero value ends everything.
type Secret ¶
type Secret struct {
// contains filtered or unexported fields
}
Secret holds a code that a message carries. It redacts itself under every fmt verb, slog, JSON, and text, so a code never reaches a log by accident. Reveal returns the code.
func (Secret) MarshalJSON ¶
MarshalJSON implements json.Marshaler with the redacted form.
func (Secret) MarshalText ¶
MarshalText implements encoding.TextMarshaler with the redacted form.
type SignInOptions ¶
type SignInOptions struct {
// Device is the known-device token the browser presented, from the
// __Host-known cookie, or empty.
Device string
}
SignInOptions changes a sign-in.
type SignUpInput ¶
type SignUpInput struct {
Address string
Password string
// Binding ties the confirmation to this browser, for example a random
// value in a cookie. It is required.
Binding string
// State is passed to the NewUser hook, at most 4,096 bytes.
State []byte
}
SignUpInput is a sign-up.
type SignedIn ¶
type SignedIn struct {
// Proof is the password proof. Pass it to authhttp.SignIn or
// auth.Service.BeginSignIn, which require TOTP when the account has
// it.
Proof auth.Proof
// Verified is true when the address is confirmed, so the page can ask
// an unverified person to confirm theirs.
Verified bool
// Device, when set, is a new known-device token: store it as the
// __Host-known cookie. It gives no access; it gives this browser its
// own limit for this account, so an attacker can't slow its holder's
// sign-ins down.
Device Secret
}
SignedIn is a successful sign-in.
type StartResetOptions ¶
type StartResetOptions struct {
// Invalidate makes the current password stop working at once and ends
// every session, for a suspected compromise.
Invalidate bool
}
StartResetOptions changes a reset that an administrator starts.
type Status ¶
type Status struct {
// Address is the address as the person entered it, or empty.
Address string `json:"address"`
Verified bool `json:"verified"`
// Password is true when the account has a usable password.
Password bool `json:"password"`
ChangedAt time.Time `json:"changed_at"`
}
Status describes a user's address and password, for a settings page.
type Store ¶
type Store interface {
auth.FactorStore
auth.EmailStore
}
Store is what the package needs from a store: factors, for codes and for knowing whether an account is strong, and addresses and passwords.
type Verification ¶
type Verification uint8
Verification says when a sign-up's address must be confirmed.
const ( // VerifyFirst creates no account until the mailbox is confirmed. It is // the zero value, so the default is strict. VerifyFirst Verification = iota // VerifyLater creates the account at sign-up, with an unverified // address that can sign in at once. A sign-in after a sign-up then // shows whether the sign-up created the account: see the package's // design document. VerifyLater )