Skip to content

moonrhythm/passwordtool

Repository files navigation

passwordtool

codecov Go Report Card GoDoc

Password hashing and comparing tool

Install

go get github.com/moonrhythm/passwordtool

Usage

hashed, err := passwordtool.Hash("superman")
if err != nil {
	// ...
}
fmt.Println(hashed)

err = passwordtool.Compare(hashed, "superman")
if err == passwordtool.ErrMismatched {
	// not equal
}
if err != nil {
	// ...
}

Specific algorithm

hc := passwordtool.Bcrypt{Cost: 11}
hashed, err := hc.Hash("superman")
if err != nil {
	// ...
}

err = hc.Compare(hashed, "superman")
if err == passwordtool.ErrMismatched {
	// not equal
}
if err != nil {
	// ...
}

// or

err = passwordtool.Compare(hashed, "superman")
if err == passwordtool.ErrMismatched {
	// not equal
}
if err != nil {
	// ...
}

License

MIT