16 lines
519 B
Go
16 lines
519 B
Go
package utils
|
|
|
|
import "golang.org/x/crypto/bcrypt"
|
|
|
|
// HashPassword meng-hash plain password menggunakan bcrypt
|
|
func HashPassword(password string) (string, error) {
|
|
bytes, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
|
|
return string(bytes), err
|
|
}
|
|
|
|
// CheckPassword membandingkan plain password dengan hash yang tersimpan
|
|
func CheckPassword(hashedPassword, plainPassword string) bool {
|
|
err := bcrypt.CompareHashAndPassword([]byte(hashedPassword), []byte(plainPassword))
|
|
return err == nil
|
|
}
|