Please read this whole message before doing anything.
The easiest way by far to recover is to restore the startup volume from a backup that predates the issue. If you can't do that or don't want to, the following shortcut works sometimes. There's no assurance that it will work in your case. It's only suitable for advanced users. I can't offer instructions any more detailed than those below.
Back up all data if you haven’t already done so. There are ways to back up, even if you can’t log in. Ask for guidance if you need it. Do not attempt this procedure unless you have a current backup of all data.
Briefly, you need to rename the following folder:
/Library/Preferences
If you already know how to do that, you can skip the rest of this message. Do it, and try again to log in.
Step 1
Start up in single-user mode by holding down the key combination command-S at the startup chime. If you’re using an external USB keyboard, it must be plugged directly into a built-in port on the Mac, not into a hub. Release the keys when you see a black screen with scrolling white text. In this mode, there’s no graphical interface; just a command line. Initially, you can’t make any changes to files.
Step 2
When the text stops scrolling, and you see a line ending in a pound sign (“#”), type the following command:
mount -uw /
You must type the command exactly as given, with no mistakes.
Press the return key.
Step 3
Enter the following command:
mv /L*/Preferences /Library/Preferences.old
Again, you must get it exactly right.
Step 4
Enter the command:
exit
Press return. The text will start scrolling again, and then the system will restart. Try again to log in. If successful, you can experiment with restoring some of the contents of the Preferences folder from a backup, or if necessary, from the renamed folder Preferences.old, although you may have trouble with permissions if you do the latter. Otherwise, just recreate all system-wide settings and delete Preferences.old by dragging it to the Trash.