Merge pull request #27 from bumi/return-not-hashed-password

Return not hashed password
This commit is contained in:
Michael Bumann
2022-01-13 20:51:49 +02:00
committed by GitHub
2 changed files with 9 additions and 6 deletions

View File

@@ -34,8 +34,9 @@ func (CreateUserController) CreateUser(c echo.Context) error {
user := &models.User{}
user.Login = randStringBytes(8)
user.Password = randStringBytes(15)
security.HashPassword(&user.Password)
password := randStringBytes(15)
hashedPassword := security.HashPassword(password)
user.Password = hashedPassword
if err := db.Create(&user).Error; err != nil {
return err
@@ -45,7 +46,7 @@ func (CreateUserController) CreateUser(c echo.Context) error {
Password string `json:"password"`
}
ResponseBody.Login = user.Login
ResponseBody.Password = user.Password
ResponseBody.Password = password
return c.JSON(http.StatusOK, &ResponseBody)
}

View File

@@ -5,7 +5,9 @@ import (
)
// HashPassword : Hash Password
func HashPassword(password *string) {
bytes, _ := bcrypt.GenerateFromPassword([]byte(*password), bcrypt.DefaultCost)
*password = string(bytes)
func HashPassword(password string) string {
bytes, _ := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
password = string(bytes)
return password
}