Change Password
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.
Perform the usual steps to get the Container instance.
- Create an instance of the Device (
HID
DeviceFactory.getDevice
). - Get the instance of the Container (
HID
Device.findContainers
). - At this point, depending on the server configuration, either:
- Get the container policy (
HID
Container.getProtectionPolicy
). - Find the key whose password needs to be changed (
HID
Container.findKeys
) and its protection policy (HID
Key.getProtectionPolicy
). - Prompt the end user for the old and new passwords, and change it (
HID
PasswordPolicy.changePassword
). - 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.
Or
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);
}
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");
}
}
}