For 10.6 and earlier:
Locate the disks that came with the computer when you bought it. They are usually grey and the one you want will say something like “Mac OS X Install Disk 1” or similar. Pop it in the disk drive and restart the computer by going to the Apple menu on the top left of the screen and choosing Restart… It will ask Are you sure you want to restart your computer?
Click the Restart button and hold down the C key on your keyboard. Keep holding it while the computer starts up and it will Boot from the DVD rather than from the internal hard drive.
The first window that appears, after a while, lets you choose English as the language. Then next screen is Preparing for installation. Ignore it and look at the top of the screen and find the Utilities menu. In it you will find the Reset Password selection. Click it and a little window will open with a picture of your hard drive. Select the hard drive icon and the accounts that have been set up on the computer will appear. Select the one that needs it’s password reset and a box will appear so that you can enter the new password, twice Click the Save button and Quit the Reset Password Utility by going to it’s menu and choosing Quit, or by selecting Command+Q on the keyboard. It will ask you if you really want to quit! Then do the same at the next window and the computer will restart with your new password saved.
Eject the install DVD and use your new password.
For 10.7 and later:
Restart while holding Command and R. The computer will boot into the Recovery partition.
Go to the Utilities menu at the top of the screen and open Terminal.
Be very careful in Terminal!
Type these exact words: resetpassword
Just the same with no space, then hit the return key and a window will open where you can select the account whose password you want to reset, enter the new password twice and click the Save button.
Once that’s done quit out of the Recovery partition and retart the computer.