From 0b8c03e8c54a8d86bd8ff6d339a24574b6dccb43 Mon Sep 17 00:00:00 2001 From: LandaMm Date: Wed, 21 May 2025 21:17:50 +0200 Subject: [PATCH] feat: hash user's password on register --- internal/user/routes.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/user/routes.go b/internal/user/routes.go index eb7f80f..44bca33 100644 --- a/internal/user/routes.go +++ b/internal/user/routes.go @@ -6,6 +6,7 @@ import ( "net/http" "gitea.local/admin/hspguard/internal/repository" + "gitea.local/admin/hspguard/internal/util" "gitea.local/admin/hspguard/internal/web" "github.com/go-chi/chi/v5" ) @@ -51,10 +52,16 @@ func (h *UserHandler) register(w http.ResponseWriter, r *http.Request) { return } + hash, err := util.HashPassword(params.Password) + if err != nil { + web.Error(w, "failed to create user account", http.StatusInternalServerError) + return + } + id, err := h.repo.InsertUser(context.Background(), repository.InsertUserParams{ FullName: params.FullName, Email: params.Email, - PasswordHash: params.Password, + PasswordHash: hash, IsAdmin: false, }) if err != nil {