encrypt passwords
This commit is contained in:
@@ -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()})
|
||||||
|
|||||||
Reference in New Issue
Block a user