As long as there are no unsaved changes on the equiptment then no you shouldn't lose any configuration. That is unless password recovery has been disabled which will in that case wipe the config.
For Switches, the password recovery procedure is usually (I say this as it is model dependant and your best bet will be to google the procuder for that model) to pull the power out, hold down the mode button then connect the power again. After the ports light up (or about 30-45 seconds) you should be able to release the mode button and have entered ROMMON mode. From here, you can enter flash_init, then rename flash:config.text flash:config.text.old and then boot
This will boot into a blank switch, from there you can copy flash:config.text.old run and that will insert the config. You should then be able to change the login credentials.
Routers are a bit different in that they will have a break sequence (this is dependent on the Terminal software you are using). Once you enter the break sequence while the router is booting, you will enter ROMMON again. From here what you do next will depend on the router platform and your best bet is to google it. I know that on most IOS routers, you need to change the config-register value from 2102 to 2142 using the command confreg 0x2142 then boot.
Once the router boots, it will not have a configuration so you can enter enable mode then copy st run and the config will be loaded. Again from here change your username credentials and don't forget to change the configuration-register value back to 2102.
That should give you an idea of how to do it, but like i said, i would double check on the correct procedure for your particular model router/switch