MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / Hash

Method Hash

pkg/auth/pbkdf2/pbkdf2.go:66–76  ·  view source on GitHub ↗

Hash hashes a plain text password.

(plain string)

Source from the content-addressed store, hash-verified

64
65// Hash hashes a plain text password.
66func (p PBKDF2) Hash(plain string) (string, error) {
67 if p.SaltLength == 0 {
68 return "", errZeroLengthSalt.New()
69 }
70
71 salt := random.String(p.SaltLength)
72 hash := hash64([]byte(plain), []byte(salt), p.Iterations, p.KeyLength, p.Algorithm)
73 pass := fmt.Sprintf("%s$%s$%v$%s$%s", p.Name(), p.Algorithm, p.Iterations, salt, string(hash))
74
75 return pass, nil
76}
77
78var errInvalidPBKDF2 = errors.DefineInternal( // internal because hash is in DB.
79 "invalid_pbkdf2_format",

Callers 3

TestHashFunction · 0.95
TestHashZeroSaltFunction · 0.95
TestInvalidSaltLengthFunction · 0.95

Calls 4

NameMethod · 0.95
StringFunction · 0.92
hash64Function · 0.85
NewMethod · 0.65

Tested by 3

TestHashFunction · 0.76
TestHashZeroSaltFunction · 0.76
TestInvalidSaltLengthFunction · 0.76