I'm working on 2FA auth application implementation. Here's the proces:
My question is:
How to store login and password submitted in step 1 properly? Is it safe to store them as plain text (unencrypted)? Or maybe I should hash them first? Store in the session?
Thanks for ay advice!
Your step 5 is slightly incorrect: you do not need to validate the password a second time. Thus, you do not need to store it anywhere, you only need to keep the login.
Server-side, you should keep in the user session the authentication status: not logged, in 2fa process, fully logged (maybe with a role such as admin, etc.)
I believe this diagram from the Symfony Documentation explains it well:
Final note, if this is not for a private/educationnal purpose only, I encourage you to use a trusted library that might handle most of the process.