skip to Main Content

I have an NSSecureTextField field in my MacOS app. I want to disable the password autofill button from coming up (the "Passwords…" button). I’ve seen posts about doing it in iOS, but haven’t seen anything on Mac OS. How can I do this? Thanks

4

Answers


  1. Note: This answer applies to iOS and UIKit, not macOS

    I agree with Alexander, please don’t 🙂

    But if you must, it would stop from offering autofill by setting the fields UITextContentType Value property to either .newPassword or .oneTimeCode as described here.

    Login or Signup to reply.
  2. Yes, Michael Rourke is right – using autofill in cocoa apps causes many problems. If for example I develop an app with a native register screen, user will see the autofill provider which propose existed passwords instead to offer a new one. It’s only the one way to hide provider – oneTimeCode. But user could get an empty transparent pop-up (I really think we can find workarounds to hide it, eg use window.makeFirstResponder(textField)) and it’s not the most big problem.

    As for me the biggest problem is an inability to save new credentials to the icloud keychain and link it with your web domain (But I could be wrong:) ). It is strange to create a password in the application without the possibility of its subsequent use when logging in.

    I think It’s a cause why apple didn’t add a new password to the Big Sure – may be they have some strange problems with creating new record to the keychain using cocoa autofill.

    In Zeplin app guys use such workaround as a native login and website registration – so safari creates a record in the keychain, app uses auto fill to login.

    I’m pretty sure they’ll add a new password in the next versions of the mac os, but it would be better if they finish this feature completely and then release it. They just killed the ability to use it normally in the next version of Mac OS because previous versions (like the current Big Sur) support it poorly.

    PS
    If a user has a lot of passwords from the current domain and he quickly drives in a password, then there is a high probability of an emergency disconnection of the provider (pop-up).

    Login or Signup to reply.
  3. It is possible to disable password autofill, due to the current default behaviour of showing the autofill button on the first NSSecureTextField in a window. But it is a kludge.

    I find that if you create a dummy NSSecureTextField above the field of concern, and hide it behind another pre-existing field, you can avoid the autofill button appearing. I set this dummy field with NSTextContentTypeOneTimeCode.

    Note this only works if the dummy NSSecureTextField is in the key view loop, so hiding it, or setting refusesFirstResponder doesn’t help. This also means you need to handle the case where the end user is tabbing from field to field, so as to skip the dummy field.

    The focus skipping can be achieved by detecting the completion of editing of the previous field (controlTextDidEndEditing:) and changing the focus if and only if the focus is on the dummy field.

    All a bit complex for something that could be simply solved with an appropriate NSTextContentType!

    Login or Signup to reply.
  4. After some reverse-engineering, I’ve found that the following subclass will disable the autofill behavior:

    @interface NoAutofillSecureTextField : NSSecureTextField
    @end
    @implementation NoAutofillSecureTextField
    - (BOOL)_isPasswordAutofillEnabled
    {
        return NO;
    }
    @end
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search