If you have forgotten the password of your cisco switch, you should follow the procedure for password recovery:
1- Power up the device after connecting the device with the console.

2-In order to start our device in recovery mode, we start by pressing the mode button at the bottom left of our switch. We need to use the Ctrl + Break or Ctrl + c key combination after the connection is established for the switches that do not have a Mode button.

3- After that, type the following commands
switch: flash_init switch: load_helper switch: dir flash

4- Then the name of this file should be changed temporarily so that we cannot get the initial configuration when we reboot.
switch: rename flash:config.text flash:config.old switch: boot
5- Then the switch will reboot. The name of the file is no longer the initial configuration, so the device will open without the password.
6-In the device we access without a password, we revert the file we changed back to.
Switch>en Switch# Switch#rename flash:config.old flash:config.text Switch#copy flash:config.text system:running-config
7- Create a new password and save the configuration.
Switch# conf t Switch (config)#enable secret password Switch (config)#line vty 0 15 Switch (config-line)#password password Switch (config-line)# exit Switch(config)#exit Switch#copy running-config startup-config