You will need to boot the Mac into the terminal mode. To do it, restart the Mac and press Command (Apple symbol) + S. A bunch of text will be displayed on your screen. This is the Unix loading process of your OS. Wait until the terminal appears then use the following commands.
Mount the file-system using : mount -uw /
Load the system resources: launchctl load /System/Library/LaunchDaemons/com.apple.DirectoryServices.plist
If you don't know the username type: ls /Users
Use the following command to change the password (enter it twice): passwd USERNAME
Reset the keychain. Doing this will also remove any other passwords stored in the keychain, but if you choose to skip it, keychain will not recognize your new password: rm -rf /Users/username/Library/Keychains/login.keychain
After all these steps, type reboot to reboot your Mac and log in with your password.
Note: This procedure works for Mac OSX 10.5.x.