code: public static ApiDynamicActionImplementor getSetCredentialsForUserApiAction(
  			final AuthenticationMethodType methodType) {
  		return new ApiDynamicActionImplementor(ACTION_SET_CREDENTIALS, new String[] { PARAM_USERNAME,
  				PARAM_PASSWORD }, null) {
  
  			@Override
  			public void handleAction(JSONObject params) throws ApiException {
  				Context context = ApiUtils.getContextByParamId(params, UsersAPI.PARAM_CONTEXT_ID);
  				int userId = ApiUtils.getIntParam(params, UsersAPI.PARAM_USER_ID);
  				// Make sure the type of authentication method is compatible
  				if (!methodType.isTypeForMethod(context.getAuthenticationMethod()))
  					throw new ApiException(ApiException.Type.ILLEGAL_PARAMETER,
  							"User's credentials should match authentication method type of the context: "
  									+ context.getAuthenticationMethod().getType().getName());
  
  				// NOTE: no need to check if extension is loaded as this method is called only if
  				// the Users
  				// extension is loaded
  				ExtensionUserManagement extensionUserManagement = Control
  						.getSingleton().getExtensionLoader().getExtension(ExtensionUserManagement.class);
  				User user = extensionUserManagement.getContextUserAuthManager(context.getIndex())
  						.getUserById(userId);
  				if (user == null)
  					throw new ApiException(ApiException.Type.USER_NOT_FOUND, UsersAPI.PARAM_USER_ID);
  				// Build and set the credentials
  				UsernamePasswordAuthenticationCredentials credentials = new UsernamePasswordAuthenticationCredentials();
  				credentials.username = ApiUtils.getNonEmptyStringParam(params, PARAM_USERNAME);
  				credentials.password = ApiUtils.getNonEmptyStringParam(params, PARAM_PASSWORD);
  				user.setAuthenticationCredentials(credentials);
  			}
  		};
  	}
docs: Gets the api action for setting a {@link UsernamePasswordAuthenticationCredentials} for an
  User.
  
  @param methodType the method type for which this is called
  @return the sets the credentials for user api action