Documentation
¶
Overview ¶
Package auth does the argon2id password hashing and makes the session and invitation tokens.
Index ¶
Constants ¶
const ( // TagPasswordHashMalformed marks a stored password hash that is not a valid // argon2id PHC string or whose parameters are out of range. TagPasswordHashMalformed = "PasswordHashMalformed" // TagPasswordHashUnsupported marks a stored password hash made by an // algorithm or a version that Verify does not support. TagPasswordHashUnsupported = "PasswordHashUnsupported" )
Variables ¶
This section is empty.
Functions ¶
func NewToken ¶
NewToken returns a random token: 32 bytes from the system's random source, in base64url without padding (43 characters). Session and invitation tokens are made with it; the database keeps only HashToken of them.
func TokensEqual ¶
TokensEqual reports whether a and b are the same string, in time that does not depend on where they differ.
Types ¶
type Hasher ¶
type Hasher struct {
// contains filtered or unexported fields
}
Hasher hashes and verifies passwords with argon2id. The zero value is not usable: make one with DefaultHasher (or FastHasher in tests). A Hasher holds no state besides its parameters, so it is safe for concurrent use.
func DefaultHasher ¶
func DefaultHasher() Hasher
DefaultHasher returns the Hasher of the running program: argon2id with 64 MiB of memory, 3 iterations and 2 threads.
func FastHasher ¶
func FastHasher() Hasher
FastHasher returns a Hasher with tiny parameters so that tests run quickly. It is for tests only: its hashes are not safe to keep.
func (Hasher) Hash ¶
Hash returns the argon2id hash of password in the PHC string format: $argon2id$v=19$m=65536,t=3,p=2$<salt>$<key>, with the salt and the key in standard base64 without padding. The salt is random, so hashing the same password twice gives two different strings.
func (Hasher) MemoryBytes ¶ added in v1.1.0
MemoryBytes is the memory one hash or one check of a password takes, which the Go runtime keeps as part of the process after the call: 64 MiB for DefaultHasher.
func (Hasher) Verify ¶
Verify reports whether password matches encoded, a string made by Hash. It uses the parameters stored in encoded, not those of h, so hashes made with older parameters keep working. A wrong password is false and a nil error. A string that is not a valid hash is a PasswordHashMalformed error, and one made by another algorithm or version is a PasswordHashUnsupported error.