To reset a login password in OS X Mountain Lion or later, restart the Mac and hold down Command-R to boot into the Recovery HD partition. From the Utilities menu, choose Terminal to open it. In Terminal type:
and press Return.
In macOS Sierra and macOS High Sierra, an Reset Password assistant will launch. Choose the user account or admin account you want to reset the password for. Enter a new password, confirm the new password, set (if you like) a password hint and then click on "Next" to set the new password for the account in question. Choose to "Restart" the Mac and when the Mac boots up, use the newly reset password to login to the computer.
In OS X Mountain Lion, OS X Mavericks, OS X Yosemite and OS X El Capitan, a Reset Password window will appear that will list all the bootable volumes attached to your Mac. Select the volume that contains the account you want to reset and choose the user name that needs its password reset. Enter and verify a new passwords in the appropriate fields and, if you like, enter a password hint. Click Save and the new password is applied to the account.