Resetting the User Password

A user can reset their password if they forget it.

The user can execute the password reset without logging in. Once the password is reset, the user access token obtained by logging in with the old password will be invalided. The user needs to relogin with the new password.

New password after reset

A new password will become valid after resetting the old password. The new password is determined by one of the following ways:

  • Auto-generate by Kii Cloud (Default)
  • Manually set by the user

You can configure the new password generation method on the developer portal. See Configuring the generation of a new password.

Resetting the password

A user can use either email or SMS when resetting their password. For SMS, you can set either a URL link or PIN code for resetting the password.

Resetting by email

Execute the resetPassword method with the ID of the target user set in the first argument and KiiEMAIL/KiiNotificationMethod.EMAIL set in the second argument. We are using the verified email address for specifying the target user in the sample code below; you can also use the user ID and the verified phone number.

Swift 3:

  • do {
      // Send an email including a link for password reset.
      try KiiUser.resetPasswordSynchronous("user_123456@example.com", notificationMethod: KiiNotificationMethod.EMAIL)
    } catch let error as NSError {
      // Handle the error.
      return
    }
  • // Send an email including a link for password reset.
    KiiUser.resetPassword("user_123456@example.com", notificationMethod: KiiNotificationMethod.EMAIL) { (error) -> Void in
      if error != nil {
        // Handle the error.
        return
      }
    }

Objective-C:

  • NSError *error;
    
    // Send an email for password reset.
    [KiiUser resetPasswordSynchronous:@"user_123456@example.com"
                   notificationMethod:KiiEMAIL
                                error:&error];
    
    if (error != nil) {
      // Handle the error.
      return;
    }
  • // Send an email including a link for password reset.
    [KiiUser resetPassword:@"user_123456@example.com"
        notificationMethod:KiiEMAIL
                     block:^(NSError *error) {
                       if (error != nil) {
                         // Handle the error.
                         return;
                       }
                     }];

When you execute the method, the user will receive an email with the URL link for resetting their password. The user's email address must be verified beforehand; you cannot use this method if the email address is unverified.

You can customize the content of the email on the developer portal. See Customizing Email/SMS Templates for the details.

The action that will take place when the user clicks the URL link depends on the configuration made on the developer portal.

  • Auto-generate by Kii Cloud: The password will be reset, and the auto-generated password will be notified to the user via email.

  • Manually set by the user: The user will be directed to the web page for entering a new password. When the user enters a new password, the password will be reset, and the specified new password becomes valid.

Execute the resetPassword method with the ID of the target user set in the first argument and KiiSMS/KiiNotificationMethod.SMS set in the second argument. We are using the verified phone number for specifying the target user in the sample code below; you can also use the user ID and the verified email address.

Swift 3:

  • let phoneNumber = "+81900011100"
    
    do {
      // Send an SMS message including a link for password reset.
      try KiiUser.resetPasswordSynchronous(phoneNumber, notificationMethod: KiiNotificationMethod.SMS)
    } catch let error as NSError {
      // Handle the error.
      return
    }
  • let phoneNumber = "+81900011100"
    
    // Send an SMS message including a link for password reset.
    KiiUser.resetPassword(phoneNumber, notificationMethod: KiiNotificationMethod.SMS) { (error) -> Void in
      if error != nil {
        // Handle the error.
        return
      }
    }

Objective-C:

  • NSError *error;
    NSString *phoneNumber= @"+81900011100";
    
    // Send an SMS message including a link for password reset.
    [KiiUser resetPasswordSynchronous:phoneNumber
                   notificationMethod:KiiSMS
                                error:&error];
    
    if (error != nil) {
      // Handle the error.
      return;
    }
  • NSString *phoneNumber= @"+81900011100";
    
    // Send an SMS message including a link for password reset.
    [KiiUser resetPassword:phoneNumber
        notificationMethod:KiiSMS
                     block:^(NSError *error) {
                       if (error != nil) {
                         // Handle the error.
                         return;
                       }
                     }];

When you execute the method, the user will receive an SMS with the URL link for resetting their password. The user's phone number must be verified beforehand; you cannot use this method if the phone number is unverified.

You can customize the content of the SMS message on the developer portal. See Customizing Email/SMS Templates for the details.

The action that will take place when the user clicks the URL link depends on the configuration made on the developer portal.

  • Auto-generate by Kii Cloud: The password will be reset, and the auto-generated password will be notified to the user via SMS.

  • Manually set by the user: The user will be directed to the web page for entering a new password. When the user enters a new password, the password will be reset, and the specified new password becomes valid.

Resetting by SMS with a PIN code

Execute the resetPassword method with the ID of the target user set in the first argument and KiiSMS_PIN/KiiNotificationMethod.SMS_PIN set in the second argument. We are using the verified phone number for specifying the target user in the sample code below; you can also use the user ID and the verified email address.

Swift 3:

  • let phoneNumber = "+81900011100"
    
    do {
      // Send an SMS message including a PIN code for password reset.
      try KiiUser.resetPasswordSynchronous(phoneNumber, notificationMethod: KiiNotificationMethod.SMS_PIN)
    } catch let error as NSError {
      // Handle the error.
      return
    }
  • let phoneNumber = "+81900011100"
    
    // Send an SMS message including a PIN code for password reset.
    KiiUser.resetPassword(phoneNumber, notificationMethod: KiiNotificationMethod.SMS_PIN) { (error) -> Void in
      if error != nil {
        // Handle the error.
        return
      }
    }

Objective-C:

  • NSError *error;
    NSString *phoneNumber= @"+81900011100";
    
    // Send an SMS message including a PIN code for password reset.
    [KiiUser resetPasswordSynchronous:phoneNumber
                   notificationMethod:KiiSMS_PIN
                                error:&error];
    
    if (error != nil) {
      // Handle the error.
      return;
    }
  • NSString *phoneNumber= @"+81900011100";
    
    // Send an SMS message including a PIN code for password reset.
    [KiiUser resetPassword:phoneNumber
        notificationMethod:KiiSMS_PIN
                     block:^(NSError *error) {
                       if (error != nil) {
                         // Handle the error.
                         return;
                       }
                     }];

When you execute the method, the user will receive an SMS with the PIN code for resetting their password. The user's phone number must be verified beforehand; you cannot use this method if the phone number is unverified.

Next, execute the completeResetPassword method with the ID of the target user set in the first argument and the obtained PIN code set in the second argument.

Swift 3:

  • let phoneNumber = "+81900011100"
    let pinCode = "123456"
    let passWord = "new_password_00"
    
    do {
      // Reset the password.
      try KiiUser.completeResetPasswordSynchronous(phoneNumber, pinCode: pinCode, password: passWord)
    } catch let error as NSError {
      // Handle the error.
      return
    }
  • let phoneNumber = "+81900011100"
    let pinCode = "123456"
    let passWord = "new_password_00"
    
    // Reset the password.
    KiiUser.completeResetPassword(phoneNumber, pinCode: pinCode, password: passWord) { (error) -> Void in
      if error != nil {
        // Handle the error.
        return
      }
    }

Objective-C:

  • NSError *error;
    NSString *phoneNumber= @"+81900011100";
    NSString *pinCode = @"123456";
    NSString *passWord = @"new_password_00";
    
    // Reset the password.
    [KiiUser completeResetPasswordSynchronous:phoneNumber
                                      pinCode:pinCode
                                     password:passWord
                                        error:&error];
    
    if (error != nil) {
      // Handle the error.
      return;
    }
  • NSString *phoneNumber= @"+81900011100";
    NSString *pinCode = @"123456";
    NSString *passWord = @"new_password_00";
    
    // Reset the password.
    [KiiUser completeResetPassword:phoneNumber
                           pinCode:pinCode
                          password:passWord
                             block:^(NSError * _Nullable error) {
                             if (error != nil) {
                               // Handle the error.
                               return;
                             }
                           }];

How the completeResetPassword method is to be executed and what kind of action will take place after executing the method depend on the configuration made on the developer portal.

  • Auto-generate by Kii Cloud: Specify a nil in the third argument (If the argument is not nil, it will be ignored). When the method is executed successfully, the password will be reset, and the auto-generated password will be notified to the user via SMS.

  • Manually set by the user: Specify the new password in the third argument. When the method is executed successfully, the password will be reset, and the specified password becomes valid.