5

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

6
  • "I want to disable the password autofill button from coming up" Please don't.
    – Alexander
    Jan 26, 2021 at 19:33
  • Why not? You can do it in iOS. There is a potential bug in the OS where this button will show up on the screen in a random place even though my app is hidden. I can't figure out why, so I just want to turn that off completely.
    – Ray
    Jan 26, 2021 at 20:48
  • Because it's a bad UX. People are increasingly using password managers. Going out of your way to disable features that work "for free" doesn't make sense.
    – Alexander
    Jan 26, 2021 at 20:50
  • 2
    Makes sense not to do it. Better to fix the actual display issue you are having.
    – hkdalex
    Jan 27, 2021 at 12:11
  • 1
    The autofill behaviour seems to apply to the first visible NSSecureTextField in a window. No labels are required, and hiding it excludes it from consideration. I also note that NSSecureTextFields within a sheet do not have this behaviour.
    – MichaelR
    May 7, 2021 at 23:13

4 Answers 4

2

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!

1
  • BTW, remember this is in the context of a password manager app. So the default behaviour makes no sense at all.
    – MichaelR
    May 8, 2021 at 11:17
1

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).

1
0

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.

4
  • 2
    Would that be a good solution? If it is neither a new password nor one-time code field, then why hack it in this way. Better leave the functionality as is and explore the bug more for a real fix.
    – hkdalex
    Jan 27, 2021 at 12:14
  • 1
    Wouldn't .newPassword offer to generate a new password, and oneTimeCode try to auto-fill from the last SMS message with a code?
    – Ray
    Jan 27, 2021 at 15:45
  • Yes true true it's not a newPassword or oneTimeCode but there doesn't seem to be a way to modify properties of the content type. But it sort of does what the OP is asking for.
    – sichy
    Feb 8, 2021 at 8:54
  • 1
    Unfortunately .newPassword isn't available with Appkit, only UIKit. I've tried .oneTimeCode but this causes different problems (a large empty transparent pop-up window appears).
    – MichaelR
    Feb 11, 2021 at 5:51
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.