1 min read

Password Validation

Last Updated - Platform 25.0 - SDK 20.0

At the moment we only provide two of ways to set password validation; which is essentially static vs dynamic (legacy).

Using Code

This method is preferable, but be advised that this approach will hardcode the rules requiring an app update to change them in the future. Make sure to increment your MightyBot version for this release incase you need to force update in the future.

  1. Open your AppModule to the setUpDependencies function (called from didAddToPlatform).
  2. Start by decorating the passwordInputView as follows.
func setUpDependencies() {
Container.shared.views.passwordInputView.decorate { newInstance(mutating: $0) { view in
// Set up view here...
}}
}
  1. Set the OS password rules using Apple's password rules tool and syntax (this is not regex).
view.passwordRules = UITextInputPasswordRules(descriptor: "minlength: 8; required: lower; required: upper;")
  1. Add the password validator(s); you can add more than one and break the regex up to provide granular errors.
view.validators.append(.minimum(8, error: "Your password must be at least 8 characters long"))
view.validators.append(.regex("(?=.*?[A-Z])", error: "At least one upper case character"))
view.validators.append(.regex("(?=.*?[a-z])", error: "At least one lower case character"))
view.validators.append(.forbid(.init(charactersIn: ",.;*-"), error: "Your password cannot contain special characters"))
  1. Validate your changes in the app.

You have set up your password rules and allowed the OS to suggest passwords!

Using MightyBot

Whilst this is the default approach, this method does not allow Apple to suggest strong passwords and the validation message is not localised. This method is not recommended.

  1. Head to developer.poq.io.
  2. Navigate to your app then edit your latest settings.
  3. Switch to the Config tab, find passwordValidationRegExp, then tap the edit (or copy) button.
  4. Enter your desired regex in the iPhone Value field, leave the other field blank, then tap Save.
  5. Switch to the Localization tab, find invalidPasswordText, then tap the edit (or copy) button.
  6. Enter an error message describing the password validation rules, then tap Save.
  7. Validate your changes in the app (make sure you're using the correct PoqApiVersion).

You have set up your password input views using MightyBot.