From 83559faa4dfcb8eb267633622aef501c3c5d44a8 Mon Sep 17 00:00:00 2001 From: valitovgaziz Date: Mon, 29 Sep 2025 00:58:34 +0500 Subject: [PATCH] new file: internal/utils/password.go Add password utils hashPass and CheckPass functions --- serv_golang_rest_api/internal/utils/password.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 serv_golang_rest_api/internal/utils/password.go 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