Please read this whole message before doing anything.
This procedure is only suitable for advanced users, preferably with command-line experience. It works sometimes. There's no assurance it will work in your case. If you don’t understand the directions or don’t feel able to carry them out, STOP.
Back up all data if you haven’t already done so. There are ways to back up, even if you can’t log in. Before proceeding,you must be sure you can restore everything to the state it’s in now. If you’re not absolutely sure you can do that,STOP.
Briefly, you need to delete the following file:
/Library/Preferences/com.apple.loginwindow.plist
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. If you don’t feel able to do that, STOP.
Press the return key.
Step 3
Enter the following command:
rm -i /L*/*/*login*
Again, you must get it exactly right. You should be prompted to remove a file named exactly "com.apple.loginwindow.plist". Press the Y key and then return to confirm. Press the N key and then return if you get any other response
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.