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. Invoke the authenticateSynchronous method with a combination of a username (or a phone number or an email address) and a password.

Swift 3:

  • let username = "user123456"
    let password = "123ABC"
    
    do{
      // Authenticate a user.
      try KiiUser.authenticateSynchronous(username, withPassword: password)
    }catch let error as NSError {
      // Handle the error.
      return
    }
  • let username = "user123456"
    let password = "123ABC"
    
    // Authenticate a user.
    KiiUser.authenticate(username, withPassword: password) { (user :KiiUser?, error : Error?) -> Void in
      if (error != nil) {
        // Handle the error.
        return
      }
    }

Objective-C:

  • NSString *username = @"user123456";
    NSString *password = @"123ABC";
    
    NSError *error;
    
    // Authenticate a user.
    [KiiUser authenticateSynchronous:username
                        withPassword:password
                            andError:&error];
    if (error != nil) {
      // Handle the error.
      return;
    }
  • NSString *username = @"user123456";
    NSString *password = @"123ABC";
    
    // Authenticate a user.
    [KiiUser authenticate:username
             withPassword:password
                 andBlock:^(KiiUser *user, NSError *error) {
      if (error != nil) {
          // Handle the error.
          return;
      }
    }];

Investigating failed logins

The error property of the NSError will return 302 if the specified user does not exist or if the password is invalid. The code 302 is also returned if the specified user is currently disabled by the app administrator. See Error details 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.