Change PIN

Changing PIN

The UserClient offers a method to change PIN for currently logged in user profile. This methods is called changePin and requires one argument:

  • OneginiChangePinHandler the changed PIN handler to return the result of change PIN action.

The SDK will handle flow of changing the PIN using OneginiPinAuthenticationRequestHandler and OneginiCreatePinRequestHandler handlers. Please read authenticate user with PIN topic guide to learn how to implement those two handlers.

Handler methods

  • void onSuccess() is called when PIN was changed.

  • void onError(final OneginiChangePinError oneginiChangePinError) is called when some error during changing PIN occurred.

Example code for changing PIN

  public void startChangePinFlow() {
    OneginiSDK.getOneginiClient(this).getUserClient().changePin(new OneginiChangePinHandler() {
      @Override
      public void onSuccess() {
        showToast("Change PIN action finished successfully");
      }

      @Override
      public void onError(final OneginiChangePinError oneginiChangePinError) {
        @OneginiChangePinError.ChangePinErrorType int errorType = oneginiChangePinError.getErrorType();
        if (errorType == OneginiChangePinError.USER_DEREGISTERED) {
          userDeregistered();
        } else if (errorType == OneginiChangePinError.DEVICE_DEREGISTERED) {
          new DeregistrationUtil(SettingsActivity.this).onDeviceDeregistered();
        }
        showToast(oneginiChangePinError.getErrorDescription());
      }
    });
  }

  private void userDeregistered() {
    final Intent intent = new Intent(this, LoginActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    startActivity(intent);
    finish();

    UserProfile authenticatedUserProfile = OneginiSDK.getOneginiClient(SettingsActivity.this).getUserClient().getAuthenticatedUserProfile();
    if (authenticatedUserProfile == null) {
      return;
    }
    new DeregistrationUtil(this).onUserDeregistered(authenticatedUserProfile);
  }

For more info on error handling see the error handling topic guide.

As you can see in the example above we handle only one error case - when user got deregistered (probably due to too many failure PIN attempts). Please note that you can handle different errors which are relevant to you. To accomplish that you should compare OneginiChangePinError#getErrorType() value with OneginiChangePinError error type definitions. The OneginiChangePinError will also contain additional error description for debugging and possible Exception object which you can get withgetErrorDescription() and getException() methods.