encrypt passwords

This commit is contained in:
zardzul
2026-03-13 22:32:46 +01:00
parent 873cd6a57d
commit 3ffd7cfc8d
+8 -1
View File
@@ -9,6 +9,7 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/jackc/pgx/v5/pgtype" "github.com/jackc/pgx/v5/pgtype"
"golang.org/x/crypto/bcrypt"
) )
type UserHandler struct { type UserHandler struct {
@@ -65,11 +66,17 @@ func (h *UserHandler) CreateUser(c *gin.Context) {
return 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, err := h.repo.CreateUser(c.Request.Context(), db.CreateUserParams{
ID: pgID, ID: pgID,
UserName: req.UserName, UserName: req.UserName,
UserMail: req.UserMail, UserMail: req.UserMail,
Password: req.Password, // TODO: hash this before storing Password: string(hashedPassword),
}) })
if err != nil { if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})