Skip to content

Commit

Permalink
chore: Fix password mismatch error handling in UpdateSecuritySettings…
Browse files Browse the repository at this point in the history
… function
  • Loading branch information
waveyboym committed Jul 21, 2024
1 parent abc9613 commit 25e245d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
12 changes: 12 additions & 0 deletions occupi-backend/pkg/handlers/api_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,10 +514,22 @@ func UpdateSecuritySettings(ctx *gin.Context, appsession *models.AppSession) {
return
}

// check if the password match
if securitySettings.NewPassword != "" && securitySettings.NewPassword != securitySettings.NewPasswordConfirm {
ctx.JSON(http.StatusBadRequest, utils.ErrorResponse(
http.StatusBadRequest,
"Invalid request payload",
constants.InvalidRequestPayloadCode,
"New password and new password confirm do not match",
nil))
return
}

// Validate the given passwords if they exist
if securitySettings.CurrentPassword != "" && securitySettings.NewPassword != "" && securitySettings.NewPasswordConfirm != "" {
securitySetting, err := SanitizeSecuritySettingsPassword(ctx, appsession, securitySettings)
if err != nil {
logrus.Error("Failed to sanitize security settings because: ", err)
return
}

Expand Down
2 changes: 2 additions & 0 deletions occupi-backend/pkg/handlers/auth_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,12 +383,14 @@ func SanitizeSecuritySettingsPassword(ctx *gin.Context, appsession *models.AppSe
password, err := database.GetPassword(ctx, appsession, securitySettings.Email)

if err != nil {
ctx.JSON(http.StatusInternalServerError, utils.InternalServerError())
return models.SecuritySettingsRequest{}, err
}

match, err := utils.CompareArgon2IDHash(securitySettings.CurrentPassword, password)

if err != nil {
ctx.JSON(http.StatusInternalServerError, utils.InternalServerError())
return models.SecuritySettingsRequest{}, err
}

Expand Down

0 comments on commit 25e245d

Please sign in to comment.