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 (DeviceFactory.getDevice).
  2. Get the instance of the Container (Device.findContainers).
  3. At this point, depending on the server configuration, either:
    • Get the container policy (Container.getProtectionPolicy).

    Or

    • Find the key whose password needs to be changed (Container.findKeys) and its protection policy (Key.getProtectionPolicy).
  4. Prompt the end user for the old and new passwords, and change it (PasswordPolicy.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
// 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.
    var containerPolicy: ProtectionPolicy? = null
    try {
        containerPolicy = currentContainer.protectionPolicy
    } catch (e: UnsupportedDeviceException) {
        e.printStackTrace()
    } catch (e: InternalException) {
        e.printStackTrace()
    } catch (e: LostCredentialsException) {
        e.printStackTrace()
    }

    // ChangePassword operation only applies to PASSWORD or BIOPASSWORD
    if (containerPolicy!!.type == ProtectionPolicy.PolicyType.BIOPASSWORD.toString() ||
        containerPolicy!!.type == ProtectionPolicy.PolicyType.PASSWORD.toString() ) {
        val PasswordPolicy = containerPolicy as PasswordPolicy?
        try {
            PasswordPolicy?.changePassword(oldPassword, newPassword)
        } catch (ex: Exception) {
            when(ex) {
                is AuthenticationException -> { // Old Password is incorrect
                    ex.printStackTrace()
                }
                is InvalidPasswordException -> { // New Password doesn't meet policy requirements.
                    ex.printStackTrace()
                }
                is LostCredentialsException, is InternalException, is FingerprintAuthenticationRequiredException, is UnsupportedDeviceException, is FingerprintNotEnrolledException, is PasswordRequiredException, is InvalidParameterException , is PasswordNotYetUpdatableException  -> {
                    ex.printStackTrace()
                }
                else -> throw ex
            }
        }
    }
Copy
ProtectionPolicy policy = null;
    boolean result = false;

    // 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.
    try {
        policy = currentContainer.getProtectionPolicy();
    } catch (UnsupportedDeviceException e) {
        e.printStackTrace();
    } catch (InternalException e) {
        e.printStackTrace();
    } catch (LostCredentialsException e) {
        e.printStackTrace();
    }

    // ChangePassword operation only applies to PASSWORD or BIOPASSWORD
    if (policy.getType() == ProtectionPolicy.PolicyType.BIOPASSWORD.toString() ||
        policy.getType() == ProtectionPolicy.PolicyType.PASSWORD.toString()) {
        try {
            result = ((PasswordPolicy) policy).changePassword(oldPassword.toCharArray(), newPassword.toCharArray());
            Log.d(LOG_TAG,"Password changed successfully");
        } catch (AuthenticationException e) { // Old Password is incorrect
            e.printStackTrace();
        } catch (InvalidPasswordException e) { // New Password doesn't meet policy requirements.
            e.printStackTrace();
        } catch (LostCredentialsException | InternalException | FingerprintAuthenticationRequiredException | UnsupportedDeviceException | FingerprintNotEnrolledException | PasswordRequiredException | InvalidParameterException | PasswordNotYetUpdatableException e) {
            e.printStackTrace();
        }
    }