Here are the steps to change the password on the router you cannot login to; commonly known as 'password recovery'.
1. Console into the router.
2. Hard boot the router using the power switch.
3. Break into the ROMMon mode by pressing the break key sequence (Ctrl+Break) in the first 60 seconds of the boot-up process. Refer http://www.cisco.com/en/US/customer/products/hw/routers/ps133/products_tech_note09186a0080174a34.shtml for more details.
4. Change the configuration register value to 0x2142. The command is 'confreg 0x2142'. On some old routers, it is 'o/r 0x2142'* . This will turn on the 6th bit from right in the configuration-register, which makes the router to ignore the start-up configuration file in the NVRAM at start-up.
5. Now reload the router using the 'reset' command. On some old routers, the command is 'initialize' or just an 'i'*. It will load without the start-up configuration file which includes the password that is configured.
6. Since, no configuration has been copied to the RAM. The router will offer the setup mode to configure the router. Say 'No' to the setup mode.
7. Get to the router's enable mode. Since, the router has no configuration to refer to, it would not even prompt for a password.
8. (Crucial step. Make sure you dont make a mistake here! )Copy the startup-configuration to the running-configuration; use either 'copy start run' or 'configure memory'. You will have the entire configuration merged with the default configuration on the RAM including the passwords. Alternatively, you could use the command 'configure replace'.
9. If you have not encrypted the passwords, do a 'show run' and note down the passwords and proceed to step 12. Else move to step 10.
10. Change the passwords.
line con 0
For privilege mode:
enable password <password> or enable secret password <password>
Use 'service password-encryption' for password encryption, if you like.
(If there is a password and a secret password, the secret password has eminence.)
Router(config)# username <username> privilege 15 password 0 <password>
11. Now copy the running-configuration to the startup-configuration; you are copying back the previous configuration with a change - the new passwords.
12. Change the configuration-register value back to 0x2102.
13. Reload the router and login with the passwords.
14. Do a "no shut" on all the interfaces.
* 'o/r' and 'i' are used on routers like 2000, 2500, 3000, 4000, 7000. You rarely see them these days.