24 lines
583 B
Go
24 lines
583 B
Go
package bcrypt
|
|
|
|
import "golang.org/x/crypto/bcrypt"
|
|
|
|
// Verifier verifys passwords using Bcrypt
|
|
type Verifier struct {
|
|
cost int
|
|
}
|
|
|
|
// Verify verifys a Password
|
|
func (bv *Verifier) Verify(password string, hashOnDb string) error {
|
|
return bcrypt.CompareHashAndPassword([]byte(hashOnDb), []byte(password))
|
|
}
|
|
|
|
// Hash calculates a hash to be stored on the database
|
|
func (bv *Verifier) Hash(password string) (string, error) {
|
|
hash, err := bcrypt.GenerateFromPassword([]byte(password), bv.cost)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return string(hash[:]), nil
|
|
}
|