NMAPasswordPolicy

@objc
public protocol NMAPasswordPolicy

The object defining whether the password provided by a user during enrollment or when changing is valid.

  • Performs validation of the password for enrollment during a registration.

    If validation fails, the implementation must invoke the provided onError with the error. The error will be the one returned by the lastRecoverableError property.

    The implementation must guarantee that, one (and only one) of onSuccess and onError is invoked, and that the one invoked is invoked only once.

    This method will be invoked in the main/UI thread.

    Synchronous implementation example that requires password to have at least 8 characters:

    - (void)validatePasswordForEnrollment:(NSString *)password onSuccess:(void (^)(void))onSuccess onError:(void (^)(NMAPasswordEnrollmentValidationError *))onError {
        if ([self isAtLeast8CharacterLong:password]) {
            return onError([[NMAPasswordEnrollmentValidationError alloc] initWithErrorType:PasswordEnrollmentValidationErrorTypeInvalidPassword
                                                                          errorDescription:@"The password has less than 8 characters."
                                                                                     cause:NULL];);
        }
    
        onSuccess();
    }
    

    Declaration

    Swift

    func validatePasswordForEnrollment(_ password: String, onSuccess: @escaping () -> (), onError: @escaping (NMAPasswordEnrollmentValidationError) -> ())

    Parameters

    password

    the password to be validated.

    onSuccess

    the block to execute if the validation is successful.

    onError

    the block to execute with the error if the validation fails.

  • Performs validation of the password during a NMAPasswordChange operation.

    If validation fails, the implementation must invoke the provided onError with the error. The error will be the one returned by the lastRecoverableError property.

    The implementation must guarantee that, one (and only one) of onSuccess and onError is invoked, and that the one invoked is invoked only once.

    This method will be invoked in the main/UI thread.

    Synchronous implementation example that requires the password to be the same as a confirmation password provided in another field:

    - (void)validatePasswordForPasswordChange:(NSString *)password onSuccess:(void (^)(void))onSuccess onError:(void (^)(NMAPasswordChangeValidationError *))onError {
        if ([self isDifferentThanConfirmationPassword:password]) {
            return onError([[NMAPasswordChangeValidationError alloc] initWithErrorType:PasswordChangeValidationErrorTypeInvalidPassword
                                                                      errorDescription:@"The provided passwords do not match."
                                                                                 cause:NULL];);
        }
    
        onSuccess();
    }
    

    Declaration

    Swift

    func validatePasswordForPasswordChange(_ password: String, onSuccess: @escaping () -> (), onError: @escaping (NMAPasswordChangeValidationError) -> ())

    Parameters

    password

    the password to be validated.

    onSuccess

    the block to execute if the validation is successful.

    onError

    the block to execute with the error if the validation fails.