Strong Password suggestion in iOS 12+

This article explains how to enable strong password suggestion in IOS.

Image for post
Image for post

This article is a short version of this WWDC video.

Please do read my article on password autofill before proceeding 🔥🔥🔥🔥.

From iOS 12, you might have seen iOS suggesting strong password while signing up for an app. This is a new feature in iOS introduced in WWDC 2018. I will explain how it works in iOS.

Image for post
Image from WWDC video

Enabling this feature is easy. All you need to do is set the textContentType property to .newPassword:

newPasswordTextField.contentType = .newPassword

By default, the generated passwords are 20 characters long. They contain uppercase, digits, hyphen, and lowercase characters. This gives you a strong password with more than 71 bits of entropy. Apple designed this to be a strong, yet compatible with most services. It is, of course, possible for your apps to define their own custom password rules. As mentioned before, in most cases, you don’t need to do this because the default format of Automatic Strong Passwords should be compatible.

A sample default password generated if we do not provide any strong password rules is given below.

tobzi2-cyczyz-sesSyt
dekdiq-nYtwa2-magjic
remniT-xyrte1-wevsev

They contain uppercase, digits, hyphen, and lowercase characters.

However, if your app’s backend requires a separate set of rules that are not compatible with the default format of Automatic Strong Passwords, you could define your own rules. To do so, use the new password rules language in iOS 12. Apple does not have access to the credentials stored in Keychain, so users’ privacy is preserved, as well.

Say you want to require a password with at least eight characters consisting of a mix of uppercase and lowercase letters, at least one number, and at most two consecutive characters. You would add this markup:

let newPasswordTextField = UITextField()
newPasswordTextField.passwordRules = UITextInputPasswordRules(descriptor: "required: upper; required: lower; required: digit; max-consecutive: 2; minlength: 8;")

Refer to this article for more ways to customize the password rule.

You can use the Password Rules Validation Tool to create , validate and download example passwords for testing purpose etc.

Image for post
Image for post
Password validation tool

That’s it. !!

Enjoy!!

You can follow me on Medium for fresh articles. Also, connect with me on LinkedIn.

If you have any comment, question, or recommendation, feel free to post them in the comment section below!

Written by

iOS and tvOS developer, dreamer, photographer 🤨

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store