23 lines
410 B
Go
23 lines
410 B
Go
package cryptography
|
|
|
|
import "golang.org/x/crypto/bcrypt"
|
|
|
|
func BcryptHash(input string) (string, error) {
|
|
hash, err := bcrypt.GenerateFromPassword(
|
|
[]byte(input),
|
|
bcrypt.DefaultCost,
|
|
)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return string(hash), nil
|
|
}
|
|
|
|
func BcryptVerify(input string, hashed string) bool {
|
|
err := bcrypt.CompareHashAndPassword(
|
|
[]byte(hashed),
|
|
[]byte(input),
|
|
)
|
|
return err == nil
|
|
}
|