Tuesday, August 29, 2023

Mac Won’t Accept Correct Login Password

I was recently surprised to find that my Mac kept rejecting my password at boot. I’ve been using the same password for years and was sure it was correct. I typed it slowly while looking at the keys. I made sure that the Caps Lock key was not down. I also tried the MacBook Pro’s built-in keyboard, in case I’d worn through another USB Apple aluminum keyboard. macOS kept not recognizing the password and locking me out of retrying for increasing amounts of time.

I rebooted into macOS Recovery, which did accept my password and let me unlock the drive in Disk Utility. My data was safe.

I did some searching online. Most pages are about resetting your password if you’ve forgotten it. Some other users seemed to be in the same situation as me but didn’t have a solution. There were suggestions to reset the NVRAM (didn’t help) and to reset the SMC (seems to happen automatically on Apple Silicon, anyway).

Eventually I figured it out: I had been typing the correct keys, but they had been producing the wrong characters because the Dvorak keyboard layout was selected. Earlier in the day, I had been writing some code for SpamSieve so that its hotkeys would work with different keyboard layouts, even though the virtual keycodes in Events.h such as kVK_ANSI_S refer to the ANSI-standard US keyboard. To test this, I had been switching among different keyboards. Even though I had long since switched back to the QWERTY layout, the login screen had remembered a previous setting. In fact, even after I selected the proper keyboard from the menu on the login screen, it still switched back to Dvorak on the next reboot. I had to delete Dvorak in System Settings to prevent this from happening.

Update (2023-08-30): Howard Oakley:

During normal startup, before you have logged in as a user, your Mac doesn’t use the custom keyboard set for a specific user, and in older versions of macOS should use that stored in /Library/Preferences/com.apple.HIToolbox.plist, which may be quite different from any set in a user’s ~/Library/Preferences/com.apple.HIToolbox.plist file. This doesn’t appear to be true for Ventura, where the pre-login settings are now hidden.

In some cases, this can prevent passwords from being entered correctly, and can readily confuse. When there’s only a single admin user, macOS should keep settings in sync, but when there are multiple users with different keyboard settings, they can become confused.

[…]

Like all preference files, they are now maintained by a service which means that editing them directly is unlikely to do a great deal: the service will happily overwrite the files with what it thinks they should be.

That is apparently what happened to me. The service saved the wrong keyboard, i.e. not what I had selected in System Settings, even though there was only one admin user. And then it failed several times to update the login setting.

Jevgeni Mullo:

Hey, it wasn’t just for me! The difficulty that I had was macOS showing correct layout being selected, yet actually using a different one. And then, quietly not switching the layout when I actively selected desired one in the language drop-down. I was going nuts.

Carlos August:

I use both an English and Spanish layout in my MBP. Although English is the default (and the language I need to be in to type my password due to muscle memory), my MBP has been choosing the Spanish layout on first boot for years.

I have been trying to fix since day 1, no luck.

Update (2023-09-05): Howard Oakley:

This stores key settings which the M1 Mac can’t obtain from internal disk storage during the early part of the boot process. An example is the location of the boot volume to be used. In Intel Macs, these are stored in discrete memory which can be reset to factory defaults. M1 Macs are different again, in that there’s no single manoeuvre which resets the contents of NVRAM.

[…]

NVRAM contents are listed in System Information under Software > Logs > NVRAM contents, and can be edited using the nvram command in Terminal. Many of the variables contained in the NVRAM of an M1 Mac aren’t intended to mean anything to the user, nor should they be changed or removed. Among those of interest and potential use are the following:

[…]

prev-lang:kbd – the initial keyboard language, such as en-GB:2 for British external (supplied as a string).

Update (2024-02-28): Howard Oakley:

If you can’t seem to enter the right password, be very careful: don’t just keep trying in the hope that you’ll get it right, as you could end up locking up your Mac altogether.

[…]

If that doesn’t do the trick, open the keyboard menu item at the top right, and check that you’re using the correct keyboard layout for the language you’re using. Although it’s not common, sometimes this menu changes its mind, and there’s nothing worse than trying to enter a password based on an English QWERTYUIOP keyboard layout when your Mac is expecting it from a French AZERTY layout.

[…]

This may give you the option of resetting your password using your Apple ID, in which case click the arrow next to that and provide your Apple ID and its password, then follow the instructions. The alternative is to use your Recovery Key if you’ve already obtained one, which is again selected by clicking on the arrow, after which you enter the key and follow the instructions.

Previously:

9 Comments RSS · Twitter · Mastodon

This happened to me a few months ago (Mac Studio M1 Max), but I have never switched keyboard layouts (perhaps there's a keyboard shortcut for this and I'd leaned on my keyboard in exactly the right way?). I had to boot into Recovery and reset; I've not seen the issue since.

Pierre Lebeaupin

On all Macs I administer, the option to select the keyboard layout at login is enabled, if only so that a user can use the layout he is more familiar with (regardless of what is actually painted on the keycaps of the physical device); while it would not necessarily have avoided the issue in your case, it would likely have allowed you to notice and fix the discrepancy sooner.

I can only guess as to why this is not enabled by default.

@Pierre To be clear, it did show the keyboard menu at login, but I didn’t notice it for a while because I’ve never looked up there before.

I had this issue years ago on a 2015 iMac 5K. I was unable to log in because the characters that I was typing for my password were not the characters being entered into the password field. I think the only reason that I noticed it was because not all of the keystrokes registered characters at all. I don't recall how I fixed it, but I've since reinstalled the OS which likely has resolved the issue for me. I _think_ I was using FileVault with a Fusion Drive, not sure if that had any impact. I was completely unaware of any keyboard layout changes at the Login Window and wouldn't even know how to change my keyboard layout at that screen. I only use US English and I don't recall ever changing my keyboard layout.

This happened to me a couple of weeks ago as well. I certainly have not used Dvorak. May have added some layouts for additional languages, but no changes in the keys of my password (and not sure about the timeline…). One day MacOS simply didn’t login. Solution was similar: booting into safe mode, trying some reseting. Eventually, regular mode accepted the password.

I use both an English and Spanish layout in my MBP. Although English is the default (and the language I need to be in to type my password due to muscle memory), my MBP has been choosing the Spanish layout on first boot for *years*.

I have been trying to fix since day 1, no luck.

I had a very similar, but much weirder problem a few weeks ago. I had the correct layout selected, and it worked correctly, except that typing the # character generated a different character. It just so happened that this was a character in my password. The only way to figure this out and fix it was to type the password into the name field, and then try every possible key combination until I figured out how to type a #. After I logged in, the problem resolved itself, and after that, I could type the # character normally again.

There is also other problem that has been around for years. After cold booting, the initial username characters may not be entered (probably due to the Bluetooth Apple Magic Keyboard with Numeric Keypad; never had problems with wired Apple keyboards and mice which unfortunately Apple no longer sells). If you do not notice that and type the password, login is not granted, as expected. But after fixing the incomplete username, it is not accepted either after pressing the carriage return to login. You must try to login again (pressing the carriage return a second time) to be accepted. And sometimes it is not; you must re-type the already correctly typed password to login. Really frustrating.

I have been struggling with this for years. Multiple Macs sometimes would not remember their keyboard layout at the login screen, falling back to US English. Using the nvram command-line tool, I was able to set them to their localized keyboard layout, in this case, German:

nvram prev-lang:kbd=de-DE:3
nvram prev-lang-diags:kbd=de-DE%00

Howard Oakley wrote about this a while ago: https://eclecticlight.co/2021/01/21/system-management-and-nvram-on-m1-macs/

Leave a Comment