Logging in

Once users are registered with your application (after completing the user verification process if required) they will be able to log in with their username, phone number or email address.

Logging in with a password

Here is the sample code for authenticating a user.

  • String username = "user_123456";
    String password = "123ABC";
    
    try {
      // Authenticate a user.
      KiiUser user = KiiUser.logIn(username, password);
    } catch (IOException e) {
      // Handle the error.
    } catch (AppException e) {
      // Handle the error.
    }
  • String username = "user_123456";
    String password = "123ABC";
    
    // Authenticate a user.
    KiiUser.logIn(new KiiUserCallBack() {
      @Override
      public void onLoginCompleted(int token, KiiUser user, Exception exception) {
        if (exception != null) {
          // Handle the error.
          return;
        }
      }
    }, username, password);

Call the logIn method with a combination of username (or phone number or email address) and password.

When you want to authenticate a user with a local phone number, please call the logInWithLocalPhone method instead:

  • String phoneNumber = "09051903944";
    String country = "JP";
    String password = "123456";
    
    try {
      // Authenticate a user.
      KiiUser user = KiiUser.logInWithLocalPhone(phoneNumber,
                                                 password,
                                                 country);
    } catch (IOException e) {
      // Handle the error.
    } catch (AppException e) {
      // Handle the error.
    }
  • String phoneNumber = "09051903944";
    String country = "JP";
    String password = "123456";
    
    // Authenticate a user.
    KiiUser.logInWithLocalPhone(new KiiUserCallBack() {
      @Override
      public void onLoginCompleted(int token, KiiUser user, Exception exception) {
        if (exception != null) {
          // Handle the error.
          return;
        }
      }
    }, phoneNumber, password, country);

Investigating failed logins

A BadRequestException will be thrown if the specified user does not exist or if the password is invalid. A BadRequestException is also thrown if the specified user is currently disabled by the app administrator. See Types of exceptions to learn more the exception handling.

For security reasons, the SDK cannot determine which is the cause of the exception. On the other hand, the app administrator can identify the error cause by checking the developer log.