I am a beginner and I cannot find a tutorial on the Internet to send a 5-digit code (for example) by email to a user who has just registered or wants to reset his password.
I am using a Rest API under Node.js and a React.js frontend. So you have to register the user and send him an email containing a code and when the user will try to connect without his account being indicated as "active" in the database, we will ask him for a 5-digit code.
I can not find any tutorials on this practice to know how to do it the right way without security vulnerabilities.
Thank you for your understanding !
Generating a five digit code from a given set of characters is a quite easy task. Getting rid of security issues is much more difficult and depends on your required level of security.
If you send the code via unencrypted email, the security is not very high (man in the middle attacks). If you use encrypted email (PGP) it can be considered safe.
Code to generate 5 character code from a given set: