16 lines
378 B
Go
16 lines
378 B
Go
|
|
package auth
|
||
|
|
|
||
|
|
import "golang.org/x/crypto/bcrypt"
|
||
|
|
|
||
|
|
func HashPassword(password string) (string, error) {
|
||
|
|
hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
|
||
|
|
if err != nil {
|
||
|
|
return "", err
|
||
|
|
}
|
||
|
|
return string(hash), nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func CheckPassword(password, hash string) bool {
|
||
|
|
return bcrypt.CompareHashAndPassword([]byte(hash), []byte(password)) == nil
|
||
|
|
}
|