Automatic Strong Password saves wrong username

I support the automatic strong password feature on my registration screen and when I go to log in later, I discover that it has saved the wrong field from my form as the username.


I've read the documentation for password autofill and automatic strong passwords pretty thoroughly and my best guess is that something about how I have designed my view controller is confusing the "heuristics" so badly that they're ignoring the content types on my text fields, but I can't seem to find any documentation about what exactly those heuristics examine so I'm stuck.


I'm only supporting iOS 12 for now. Here's how I have the app's registration screen set up:


There is a single UIViewController containing a UIScrollView that has 4 UITextFields arranged using UIStackViews. There is a submit button at the bottom of the form that is labelled "Sign Up Now". This is all being set up via Interface Builder. The form has:


- An email address field that I've marked with content type Username and the keyboard type for email

- a field for the user's first name, with content type Given Name

- a password field that I've marked with content type New Password

- a repeat password field that I've also marked with Content Type New Password.


When I test this out, it is saving the user's first name as their username instead of the email address. The next time the user comes to the login screen in the app, their first name is suggested for the username in the login screen instead of their email address. If the user then corrects the username field and proceeds to log in, a new set of credentials are added for the associated domain with the correct username and password. I have also checked this by going to a Mac and looking in the saved passwords in Safari and I've watched it update while the user goes through these steps.


So what is going on here? How do I convince the strong password suggestion to save the right username?

Replies

I am running iOS 12.4.1 and Xcode 10.3

I am having the same issue. I have a view controller with (from top to bottom) an email, phone, and password text field.

The email field has the textContentType set to .username,

the phone text field is set to .telephoneNumber,

and the password text field set to .newPassword.

After I fill out the fields, iOS saves the password for me as expected.

When I go into settings and check what was saved, the phone number is saved as the user name instead of the email. The password is saved as it should be.


The email field is set to textContentType of .username so that should be saved as the user name.

But for some reason the phone text field is being saved, even though it's textContentType is set to .telephoneNumber.


I have tried different textContentTypes and nothing seems to work for me, the phone is always saved as the user name. I have no idea why this is not working.

Also seeing this issue running iOS 13.4 and using Xcode 11.3


My ViewController has a username textfield, a first name text field, a last name textfield, a password textfield and a confirm password textfield in that order vertically. No matter what contentType I set, the last name is used as the username when stored.



I did comeup with a solution that is rather ugly. Since the storing happens after the view hiearchy is gone, I am setting the lastname's text to the username's text right before the call to move away from my creation viewcontroller (and after the account was created). That worked in that it saved the correct information. I know it is ugly, but hopefully that helps someone.