Skip to content

go-passwd/hasher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

95 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Password hasher library for Go

test Go Report Card GoDoc

Password hashing primitives. Each hasher computes a salted, iterated digest and exposes its salt / iteration count / digest so the companion marshaller package can serialize the result in a Django-style algorithm$iterations$salt$hash format.

Installation

go get github.com/go-passwd/hasher

Usage

hshr, err := hasher.New(hasher.TypeSHA512)
if err != nil {
    log.Fatal(err)
}
hshr.SetPassword(plainTextPassword)

if hshr.Check(userInput) {
    // password matches
}

SetPassword generates a random salt and uses DefaultIter iterations when neither is set. To reuse a hash from storage, build the hasher with the original salt and iteration count:

iter := 2048
salt := "..."
password := []byte{...}
hshr, err := hasher.NewWithParams(hasher.TypeSHA256, &iter, &salt, &password)
if err != nil {
    log.Fatal(err)
}
hshr.Check(userInput)

Hashers

Type Constant
Plain text TypePlain
MD5 TypeMD5
SHA-1 TypeSHA1
SHA-224 TypeSHA224
SHA-256 TypeSHA256
SHA-384 TypeSHA384
SHA-512 TypeSHA512
SHA-512/224 TypeSHA512_224
SHA-512/256 TypeSHA512_256

PlainHasher ignores salt and iterations.

Registering custom hashers

Implement the Hasher interface (and optionally marshaller.Marshalable for serialization) and call hasher.Register:

hasher.Register("custom", func(iter *int, salt *string, password *[]byte) hasher.Hasher {
    return &MyHasher{Salt: salt, Iter: iter, Password: password}
})

Releases

No releases published

Packages

 
 
 

Contributors