Documentation ¶
Index ¶
Constants ¶
const ( // DefaultSaltByteLength is the default length (bytes) of a generated secure // random salt DefaultSaltByteLength = 64 // DefaultKeyByteLength is the default length (bytes) of the hash that will be // generated DefaultKeyByteLength = 64 // DefaultR is the number of rounds of hashing used to generated a hashed // password DefaultR = 16 // DefaultN is a CPU/memory cost parameter which must be a power of two // greater than 1 DefaultN = 16384 )
Variables ¶
This section is empty.
Functions ¶
func GenerateSalt ¶
GenerateSalt takes a byte size as an int, returns a secure random stirng to the size of byteSize.
func Hash ¶
func Hash(p1 string, p2 string, r int, n int, saltByteLength int, keyByteLength int) (string, error)
Hash hashes p1 (password) using r (rounds), n (costParam) and a securely generated salt (see GenerateSalt func).
p1 and p2 are compared using ConstantTimeCompare, if no match, err is returned.
A string in the following format is returned r:n:keyLength:salt:hashedPassword
See Validate func for password validation
func HashWithDefaults ¶
HashWithDefaults is the same as Hash, but uses the default settings
default r (rounds) = 16 default N (cpu/ memory cost) = 16386 default h (hashByteSize) = 64 default s (saltByteSize) = 64
returns a string as: r:n:keyLength:salt:hashedPassword
func Validate ¶
Validate compares password against stored hash. password is the password as a string, hashPackage is the string that has been generated by HashWithDefaults or Hash functions
returns true or false
NOTE: If this func returns any errors, calling func should log there was an error decoding said password, dont log the password but just a ref to the user in question and investigate accordingly
Types ¶
This section is empty.