From 3ffd7cfc8db464ec9ff5d14a87d3f3c79f495093 Mon Sep 17 00:00:00 2001 From: zardzul Date: Fri, 13 Mar 2026 22:32:46 +0100 Subject: [PATCH] encrypt passwords --- api/handlers/user_handler.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/api/handlers/user_handler.go b/api/handlers/user_handler.go index c9bfff6..0003e67 100644 --- a/api/handlers/user_handler.go +++ b/api/handlers/user_handler.go @@ -9,6 +9,7 @@ import ( "github.com/gin-gonic/gin" "github.com/google/uuid" "github.com/jackc/pgx/v5/pgtype" + "golang.org/x/crypto/bcrypt" ) type UserHandler struct { @@ -65,11 +66,17 @@ func (h *UserHandler) CreateUser(c *gin.Context) { return } + hashedPassword, err := bcrypt.GenerateFromPassword([]byte(req.Password), bcrypt.DefaultCost) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to hash password"}) + return + } + id, err := h.repo.CreateUser(c.Request.Context(), db.CreateUserParams{ ID: pgID, UserName: req.UserName, UserMail: req.UserMail, - Password: req.Password, // TODO: hash this before storing + Password: string(hashedPassword), }) if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})