Don't worry I'll try to remember the next time. If I try hard enough I can surely remember it even though if may be a complex,long,confusing password. The main problem is no matter what I do, once someone becomes a custom ROM user, they get addict to test new ROMs. To do that you have to either backup your data or have another device which I don't. So every time I flash, I have to start from scratch like connecting to Wifi, relogin gmail and stuff, reinstalling all apps, and relogin again. If I were a Legendary like you surely I will be more serious in security. Since I'm a newbie I won't get much much attention. But thanks anyway.
Use a password manager.
I use LastPass but their new rules about requiring you to pay to access it from multiple devices means its not suitable for free use anymore, so you should either use BitWarden, which has a mobile app and can even be self-hosted - or not, or use KeyPass XC which creates a vault on your computer as a file, to store your passwords and 2FA codes in (yes it can do that!)
Don't rely on the browser password manager because as you said, it will be wiped out during the flashing.