If that is not working for you then please try below instructions :-
1. Start your Mac while holding Command and S at the same time
2. When the scrolling text stops, type '/sbin/mount -uw /' (no quotation marks)
3. Type 'rm /var/db/.applesetupdone' (again, no quotation marks)
4. Type 'exit' (still no quotation marks)
5. Follow the instructions to create another account. Don't enter your Apple ID.
6. After getting to the desktop, open System Preferences (Apple menu > System Preferences), then click on "Users and Groups"
7. Click on the lock in the lower left hand corner, enter the password ***** set during the initial setup.
8. Click on your account, then click "Reset Password", if prompted, click "Use Separate Password"
9. Enter a new password, then click "OK"
10. Login to your original account (the one you were locked out of), then when prompted to update your Keychain password, click "Update Keychain", then enter the last password ***** successfully logged into this account with.
You only need to do steps 1 - 5 if you have no other admin account on the computer, if you have another admin account you can log into, log into that account and start from step 6.