15 lines
362 B
Go
15 lines
362 B
Go
|
package hash
|
||
|
|
||
|
import "golang.org/x/crypto/bcrypt"
|
||
|
|
||
|
func HashPassword(password string, cost int) (string, error) {
|
||
|
bytes, err := bcrypt.GenerateFromPassword([]byte(password), cost)
|
||
|
return string(bytes), err
|
||
|
}
|
||
|
|
||
|
func CheckPasswordHash(password, hash string) bool {
|
||
|
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
|
||
|
return err == nil
|
||
|
}
|
||
|
|