services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java
/**
     *  Set up a temporary password for this user.  User will have to reset this temporary password when they log
     *  in next.
     *
     * @param id
     * @param pass temporary password
     */
Set up a temporary password for this user.  User will have to reset this temporary password when they log
in next.

@param id
@param pass temporary password
Set up a temporary password for this user . User will have to reset this temporary password when they log in next . @param id @param pass temporary password
@Path("{id}/reset-password")
    @PUT
    @Consumes(MediaType.APPLICATION_JSON)
    public void resetPassword(@PathParam("id") String id, CredentialRepresentation pass) {
        auth.requireManage();
        UserModel user = session.users().getUserById(id, realm);
        if (user == null) {
            throw new NotFoundException("User not found");
        }
        if (pass == null || pass.getValue() == null || !CredentialRepresentation.PASSWORD.equals(pass.getType())) {
            throw new BadRequestException("No password provided");
        }
        UserCredentialModel cred = RepresentationToModel.convertCredential(pass);
        try {
            session.users().updateCredential(realm, user, cred);
        } catch (IllegalStateException ise) {
            throw new BadRequestException("Resetting to N old passwords is not allowed.");
        } catch (ModelReadOnlyException mre) {
            throw new BadRequestException("Can't reset password as account is read only");
        }
        if (pass.isTemporary()) user.addRequiredAction(UserModel.RequiredAction.UPDATE_PASSWORD);
        adminEvent.operation(OperationType.ACTION).resourcePath(uriInfo).success();
    }
@ Path ( "{id}/reset-password" ) @ PUT @ Consumes ( MediaType . APPLICATION_JSON ) public void resetPassword ( @ PathParam ( "id" ) String id , CredentialRepresentation pass ) { auth . requireManage ( ) ; UserModel user = session . users ( ) . getUserById ( id , realm ) ; if ( user == null ) { throw new NotFoundException ( "User not found" ) ; } if ( pass == null || pass . getValue ( ) == null || ! CredentialRepresentation . PASSWORD . equals ( pass . getType ( ) ) ) { throw new BadRequestException ( "No password provided" ) ; } UserCredentialModel cred = RepresentationToModel . convertCredential ( pass ) ; try { session . users ( ) . updateCredential ( realm , user , cred ) ; } catch ( IllegalStateException ise ) { throw new BadRequestException ( "Resetting to N old passwords is not allowed." ) ; } catch ( ModelReadOnlyException mre ) { throw new BadRequestException ( "Can't reset password as account is read only" ) ; } if ( pass . isTemporary ( ) ) user . addRequiredAction ( UserModel . RequiredAction . UPDATE_PASSWORD ) ; adminEvent . operation ( OperationType . ACTION ) . resourcePath ( uriInfo ) . success ( ) ; }
Set up a temporary password for this user.
Set up a temporary password for this user .