Changing the User Password

A user can change the password by executing the updatePassword method with the current and new passwords.

The user needs to be logged in for changing their password. Once the password is changed, the user needs to relogin with the new password.

Swift:

  • let fromPassword = "myOldPassword"
    let toPassword = "myNewPassword"
    let user = KiiUser.current()!
    
    do {
      // Change the password.
      try user.updatePasswordSynchronous(fromPassword, newPassword: toPassword)
    } catch let error as NSError {
      // Handle the error.
      return
    }
  • let fromPassword = "myOldPassword"
    let toPassword = "myNewPassword"
    let user = KiiUser.current()!
    
    // Change the password.
    user.updatePassword(fromPassword, to: toPassword) { (user :KiiUser?, error : Error?) -> Void in
      if error != nil {
        // Handle the error.
        return
      }
    }

Objective-C:

  • NSString *fromPassword = @"myOldPassword";
    NSString *toPassword = @"myNewPassword";
    NSError *error;
    KiiUser *user = [KiiUser currentUser];
    
    // Change the password.
    [user updatePasswordSynchronous:fromPassword newPassword:toPassword error:&error];
    if (error != nil) {
      // Handle the error.
      return;
    }
  • NSString *fromPassword = @"myOldPassword";
    NSString *toPassword = @"myNewPassword";
    KiiUser *user = [KiiUser currentUser];
    
    // Change the password.
    [user updatePassword:fromPassword to:toPassword withBlock:^(KiiUser *user, NSError *error) {
      if (error != nil) {
        // Handle the error.
        return;
      }
    }];