If you have forgotten about the password for your Mac’s user account, it can be reset by another local user account which has administrator privileges. If not you have to go through the laborious OS X Recovery.
Another option is to link your OS X user account with an Apple ID. You can then reset your forgotten password by signing into your Apple ID account.
To link your OS X user account with an Apple ID, go to System Preferences > Users & Groups.
Select your account and then click the Set… button that is next to “Apple ID” label. Enter your Apple ID and password when prompted. Then tick the checkbox Allow user to reset password using Apple ID.
When you subsequently enter incorrect password a number of times at OS X login screen, a message will popup to give you the option to reset your password via Apple ID login.