1 min read
Password Validation
Last Updated - Platform 25.0 - SDK 20.0At 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.
- Open your
AppModule
to thesetUpDependencies
function (called fromdidAddToPlatform
). - Start by decorating the
passwordInputView
as follows.
func setUpDependencies() { Container.shared.views.passwordInputView.decorate { newInstance(mutating: $0) { view in // Set up view here... }}}
- 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;")
- 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"))
- 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.
- Head to developer.poq.io.
- Navigate to your app then edit your latest settings.
- Switch to the Config tab, find
passwordValidationRegExp
, then tap the edit (or copy) button. - Enter your desired regex in the iPhone Value field, leave the other field blank, then tap Save.
- Switch to the Localization tab, find
invalidPasswordText
, then tap the edit (or copy) button. - Enter an error message describing the password validation rules, then tap Save.
- Validate your changes in the app (make sure you're using the correct
PoqApiVersion
).
You have set up your password input views using MightyBot.