Change Password

View this page for | |

This workflow can take place when the end user wants/needs to change their password as part of the standard application usage.

Password change can be mandated at regular intervals if the password policy specifies a maxAge value for instance. Use currentAge to determine the time since previous change password.

Note: Password expiration (maxAge) is ignored when the SilentLockPolicy is configured for use.

Perform the usual steps to get the Container instance.

  1. Create an instance of the Device (HIDDeviceFactory.getDevice).
  2. Get the instance of the Container (HIDDevice.findContainers).
  3. At this point, depending on the server configuration, either:
    • Get the container policy (HIDContainer.getProtectionPolicy).

    Or

    • Find the key whose password needs to be changed (HIDContainer.findKeys) and its protection policy (HIDKey.getProtectionPolicy).
  4. Prompt the end user for the old and new passwords, and change it (HIDPasswordPolicy.changePassword).
  5. If the current password is correct and the new password matches the Protection Policy, then the operation is successful and the password is changed. Otherwise, an error is returned/thrown.
Copy
do{
        // You can check the policy protecting the container, or alternatively a policy protecting a key.
        // Unless a specific configuration is used, they will be the same.
        let policy = try myContainer?.getProtectionPolicy()
        
        // ChangePassword operation only applies to PASSWORD or BIOPASSWORD
        if(policy?.policyType()==HIDPolicyTypePassword ||
           policy?.policyType()==HIDPolicyTypeBioPassword) {
            let passwordPolicy = policy as? HIDPasswordPolicy
            try passwordPolicy?.changePassword(oldPassword, new: newPassword)
            NSLog("Password changed successfully")
        }
    }
    catch let error as NSError {
        // HIDAuthentication if old password is incorrect
        // HIDInvalidPassword if new password does not meet policy requirements
        // HIDPasswordNotYetUpdatable if too early for password change according to protection policy
        NSLog("Failed to change password: %@",error.localizedDescription);
    }
Copy
NSError* error;

    // You can check the policy protecting the container, or alternatively a policy protecting a key.
    // Unless a specific configuration is used, they will be the same.
    id<HIDProtectionPolicy> containerPolicy = [myContainer getProtectionPolicy:&error];
    if (containerPolicy != nil) {
    
        // ChangePassword operation only applies to PASSWORD or BIOPASSWORD
        if ([containerPolicy policyType] == HIDPolicyTypePassword || [containerPolicy policyType] == HIDPolicyTypeBioPassword) {
            
            id<HIDPasswordPolicy> pwdPolicy = (id<HIDPasswordPolicy>)containerPolicy;
            [pwdPolicy changePassword:sOldPassword new:sNewPassword error:&error];
            
            if (error) {
                // HIDAuthentication if old password is incorrect
                // HIDInvalidPassword if new password does not meet policy requirements
                // HIDPasswordNotYetUpdatable if too early for password change according to protection policy
                NSLog(@"Failed to change password (%ld)",(long)[error code]);
            } else {
                NSLog(@"Password changed successfully");
            }
        }
    }