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