@@ -360,50 +360,33 @@ func (api *api) putUserSuspend(rw http.ResponseWriter, r *http.Request) {
360
360
httpapi .Write (rw , http .StatusOK , convertUser (suspendedUser , organizations ))
361
361
}
362
362
363
- func (api * api ) putUserPassword (rw http.ResponseWriter , r * http.Request ) {
363
+ func (api * api ) putUserPassword (rw http.ResponseWriter , r * http.Request ) error {
364
364
user := httpmw .UserParam (r )
365
365
366
366
var params codersdk.UpdateUserPasswordRequest
367
367
if ! httpapi .Read (rw , r , & params ) {
368
- return
369
- }
370
-
371
- // Check if the password is correct
372
- equal , err := userpassword .Compare (string (user .HashedPassword ), params .Password )
373
- if err != nil {
374
- httpapi .Write (rw , http .StatusInternalServerError , httpapi.Response {
375
- Message : fmt .Sprintf ("compare: %s" , err .Error ()),
376
- })
377
- }
378
- if ! equal {
379
- // This message is the same as above to remove ease in detecting whether
380
- // users are registered or not. Attackers still could with a timing attack.
381
- httpapi .Write (rw , http .StatusUnauthorized , httpapi.Response {
382
- Message : "invalid email or password" ,
383
- })
384
- return
368
+ return nil
385
369
}
386
370
387
371
// Check if the new password and the confirmation match
388
372
if params .NewPassword != params .ConfirmNewPassword {
389
- errors := []httpapi.Error {
373
+ requestErrors := []httpapi.Error {
390
374
{
391
375
Field : "confirm_new_password" ,
392
376
Detail : "The value does not match the new password" ,
393
377
},
394
378
}
395
379
httpapi .Write (rw , http .StatusBadRequest , httpapi.Response {
396
380
Message : fmt .Sprintf ("The new password and the new password confirmation don't match" ),
397
- Errors : errors ,
381
+ Errors : requestErrors ,
398
382
})
399
- return
383
+ return nil
400
384
}
401
385
402
386
// Hash password and update it in the database
403
387
hashedPassword , hashError := userpassword .Hash (params .NewPassword )
404
388
if hashError != nil {
405
- xerrors .Errorf ("hash password: %w" , hashError )
406
- return
389
+ return xerrors .Errorf ("hash password: %w" , hashError )
407
390
}
408
391
databaseError := api .Database .UpdateUserHashedPassword (r .Context (), database.UpdateUserHashedPasswordParams {
409
392
ID : user .ID ,
@@ -413,10 +396,11 @@ func (api *api) putUserPassword(rw http.ResponseWriter, r *http.Request) {
413
396
httpapi .Write (rw , http .StatusInternalServerError , httpapi.Response {
414
397
Message : fmt .Sprintf ("put user password: %s" , databaseError .Error ()),
415
398
})
416
- return
399
+ return nil
417
400
}
418
401
419
402
httpapi .Write (rw , http .StatusNoContent , nil )
403
+ return nil
420
404
}
421
405
422
406
func (api * api ) userRoles (rw http.ResponseWriter , r * http.Request ) {
0 commit comments