Documentation ¶
Overview ¶
Package passwd provides simple primitives for hashing and verifying password.
Index ¶
Examples ¶
Constants ¶
const ( // Argon2id constant is to select the argon flavor in Argon2Params version field Argon2id = iota // default // Argon2i constant is to select argon flavor in Argon2Params version field Argon2i )
const ( ErrParse = Error("parse error") ErrUnsupported = Error("unsupported") ErrMismatch = Error("mismatch") ErrUnsafe = Error("unsafe parameters") )
const ( Argon2idDefault = iota Argon2idParanoid ScryptDefault ScryptParanoid BcryptDefault BcryptParanoid )
Password hashing profiles available
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Argon2Params ¶
type Argon2Params struct { Version int Time uint32 Memory uint32 Thread uint8 Saltlen uint32 Keylen uint32 // contains filtered or unexported fields }
Argon2Params are the parameters for the argon2 key derivation.
type BcryptParams ¶
type BcryptParams struct {
Cost int
}
BcryptParams are the parameters for the bcrypt key derivation.
type Profile ¶
type Profile struct {
// contains filtered or unexported fields
}
Profile define the hashing profile you have select and is created using New() / NewMasked() / NewCustom()
func New ¶
New instanciate a new Profile
Example ¶
p := New(Argon2idDefault) h, err := p.Hash([]byte("mylamepass!!")) if err != nil { panic(err) } fmt.Printf("hashed('mylamepass!!'): %s\n", h)
Output: hashed('mylamepass!!'): $2id$params$*password_hash*
func NewCustom ¶
func NewCustom(params interface{}) *Profile
NewCustom instanciates a new Profile using user defined hash parameters
func NewMasked ¶
New instanciates a new masked Profile. Masked translate to the fact that no hash parameters will be provided.
Example ¶
p := NewMasked(Argon2idDefault) h, err := p.Hash([]byte("mylamepass!!")) if err != nil { panic(err) } fmt.Printf("hashed('mylamepass!!'): %s\n", h)
Output:
func (*Profile) Compare ¶
Compare method compared a computed hash against a plaintext password for the associated profile. This function is mainly here to allow to work with "masked" hashes where we don't provide the Hash parameters in the hashed values.
Example ¶
hashedPassword := "$2id$PEKC7uef8j09Tx8WHKrpwu$e1ZINFSkJz4/hM0mytQCjrEmVRRb6VtkXwAZibZhgYm" p := NewMasked(Argon2idDefault) err := p.Compare(hashedpassword, []byte("prout")) fmt.Printf("Masked Compare err: %v", err)
Output:
type ScryptParams ¶
type ScryptParams struct { N uint32 // cpu memory cost must be > 1 && %2 == 0 R uint32 // parallelization cost param -> r*p < 2^30 (go implementation specific) P uint32 // parallelization cost param -> r*p < 2^30 (go implementation specific) Saltlen uint32 // 128 bits min. Keylen uint32 // 128 bits min. // contains filtered or unexported fields }
ScryptParams are the parameters for the scrypt key derivation.