Files
simrsx-be/pkg/password/password.go
2025-08-13 14:26:14 +07:00

18 lines
375 B
Go

package password
import (
"golang.org/x/crypto/bcrypt"
)
var Cost = 10 // can be set by consumer
func Hash(password string) (string, error) {
bytes, err := bcrypt.GenerateFromPassword([]byte(password), Cost)
return string(bytes), err
}
func Check(password, hash string) bool {
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
return err == nil
}