This is a simple system created to understand how to generate random OTPs and send to email, just like most online transactions and webapps use. It is created using JavaScript and Node.js
HOW TO USE:
- Install Node in your system if you don't have it already. Verify the installation of node in command prompt
- Use node -v
- npm -v
- Setup Backend (NodeJS) can be done by creating a directory with
- mkdir your-name-choice
- cd your-name-choice
- Initialize this project with the required packages npm init -y
- Create index,js and .env files
- Inside the .env file, copy this
- EMAIL_USER=your_email@gmail.com EMAIL_PASS=your_app_password_or_password
Disclaimer: If you are using your Google account, Google might block your login attempt because Google considers this as a 'less secure app'. What you can do?
Generate an App Password.
- This needs to have your 2-step verification enabled.
- Go to App Passwords section in your Google Account (Should be under Security).
- Select Mail and Other as the app you are usig, name it like 'otp system password' and generate the password.
- Google will provide you with a 16-character password which you need to replace in your .env file, under EMAIL_PASS
- Update your .env file.
- Copy the index.js file, make changes if you need any modifications and run the backend server by firing this command
- node index.js
- This will print a randomly generated 6-character otp on the console and will send the OTP on your registered email address.