2

I am implementing a "save password" feature on sign up, where I have 3 text fields: Username, password and confirm password.

My problem is if I remove "confirm password" text field, a "save password" PopUp comes and I am able to save the password, but I want a "confirm password" text field as well. As soon as I add a "confirm password" text field it stops showing me "save password" PopUp.

This is my code:

func setupTextFields() { // USERNAME FIELD usernameTextField.delegate = self usernameTextField.textContentType = .username usernameTextField.keyboardType = .emailAddress usernameTextField.autocapitalizationType = .none usernameTextField.autocorrectionType = .no usernameTextField.isSecureTextEntry = false // PASSWORD passwordTextField.delegate = self passwordTextField.textContentType = .newPassword passwordTextField.isSecureTextEntry = true passwordTextField.autocapitalizationType = .none passwordTextField.autocorrectionType = .no //CONFIRM PASSWORD confirmpasswordTextField.delegate = self confirmpasswordTextField.textContentType = .newPassword confirmpassowrdTextField.isSecureEntry = true confirmpasswordTextField.autocapitalizationType = .none confirmpasswordTextField.autocorrectionType = .no } 

The method I am calling in ViewDidLoad() What could be the reason?

2
  • can you please post your whole class file Commented Nov 27 at 5:35
  • I have edited my original question. Commented Nov 27 at 7:24

1 Answer 1

0

The issue is that iOS's password autofill system gets confused when both password fields have textContentType = .newPassword. The system doesn't know which one to save.

Solution:

Set the confirm password field's textContentType to nil:

swift

// PASSWORD FIELD passwordTextField.delegate = self passwordTextField.textContentType = .newPassword passwordTextField.isSecureTextEntry = true passwordTextField.autocapitalizationType = .none passwordTextField.autocorrectionType = .no // CONFIRM PASSWORD - Don't set textContentType confirmPasswordTextField.delegate = self confirmPasswordTextField.textContentType = nil // This is the key change confirmPasswordTextField.isSecureTextEntry = true confirmPasswordTextField.autocapitalizationType = .none confirmPasswordTextField.autocorrectionType = .no 

This tells iOS that only the first password field should be saved, and the confirm field is just for validation. The "save password" popup should now appear correctly.

Make sure you're validating that both passwords match in your code before allowing the user to proceed with sign up.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.