ARTICLE AD BOX
Asked today
Viewed 46 times
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,7088 gold badges44 silver badges55 bronze badges
2
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 = .noThis 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.
3,03035 silver badges49 bronze badges
Explore related questions
See similar questions with these tags.
