Documentation ¶
Index ¶
- Constants
- Variables
- func Compare(hash, password []byte) (equal bool, err error)
- func CompareString(hash, password string) (equal bool, err error)
- func Hash(password []byte) (hash []byte, err error)
- func HashAlgString(password string, algs ...Alg) (hash string, err error)
- func HashString(password string) (hash string, err error)
- func HashWith(password []byte, algs ...Alg) (hash []byte, err error)
- func SetPrecedence(algs ...Alg)
- type Alg
- type Algorithm
- type Argon2Config
- type Argon2i
- type Argon2id
- type Bcrypt
- type BcryptConfig
- type SaltConfig
- type Scrypt
- type ScryptConfig
Constants ¶
const ( AlgBcrypt Alg = 1 AlgScrypt = 2 AlgArgon2i = 3 AlgArgon2id = 4 )
Variables ¶
var DefaultArgon2Config = Argon2Config{ Salt: DefaultSaltConfig, Time: 1, Memory: 64 * 1024, Threads: 4, KeyLen: 32, }
var DefaultBcryptConfig = BcryptConfig{ Cost: bcrypt.DefaultCost, }
var DefaultSaltConfig = SaltConfig{
Length: 16,
}
var DefaultScryptConfig = ScryptConfig{ N: 32768, R: 8, P: 1, KeyLen: 32, Salt: DefaultSaltConfig, }
Functions ¶
func Compare ¶
Compare takes the hashed password and the plain text password a validates they are the same. It assumes the hash was generated using Hash or HashAlg which include the hashing algorithm used.
func CompareString ¶
CompareString is the same as Compare, but the password and hash are strings
func Hash ¶
Hash takes a plain text password and hashes it using the best available algorithm. The algorithm used is included at the beginning of the hash result.
func HashAlgString ¶
HashAlgString is the same as HashAlg, but the password and hash are strings
func HashString ¶
HashString is the same as Hash, but the password and hash are strings
func HashWith ¶
HashAlg takes a plain text password and hashes using the first available algorithm type provided. The algorithm used is included at the beginning of the hash result
func SetPrecedence ¶
func SetPrecedence(algs ...Alg)
Set the precedence of which algorithms to use for encoding. A single hashing algorith can be used if desired
Types ¶
type Alg ¶
type Alg = uint8
func GetHashAlg ¶
Returns the algorithm used for a given hash or an error if the hash is invalid
type Argon2Config ¶
type Argon2Config struct { Salt SaltConfig Time uint32 Memory uint32 Threads uint8 KeyLen uint32 }
type BcryptConfig ¶
type BcryptConfig struct {
Cost int
}
type SaltConfig ¶
type SaltConfig struct {
Length int
}
type Scrypt ¶
type Scrypt struct {
Config ScryptConfig
}
type ScryptConfig ¶
type ScryptConfig struct { N int R int P int KeyLen int Salt SaltConfig }