diff --git a/serv_golang_rest_api/internal/utils/password.go b/serv_golang_rest_api/internal/utils/password.go new file mode 100644 index 0000000..bd5dae7 --- /dev/null +++ b/serv_golang_rest_api/internal/utils/password.go @@ -0,0 +1,14 @@ +// utils/password.go +package utils + +import "golang.org/x/crypto/bcrypt" + +func HashPassword(password string) (string, error) { + bytes, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost) + return string(bytes), err +} + +func CheckPasswordHash(password, hash string) bool { + err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password)) + return err == nil +} \ No newline at end of file