ElectiveHub icon indicating copy to clipboard operation
ElectiveHub copied to clipboard

Add OTP feature

Open piyush-gangrade opened this issue 1 year ago • 12 comments

PR #39

Add verifyOTP.jsx for sending and verifying OTP, and update Login.jsx and Signup.jsx accordingly.

Details: After users log in or sign up, they will navigate to the 'verify' route where they have to enter the OTP sent to their email. After submitting the OTP, if it is valid, a token will be sent to the user.

Screenshot (60)

piyush-gangrade avatar May 11 '24 13:05 piyush-gangrade

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
elective-hub ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 13, 2024 6:39pm

vercel[bot] avatar May 11 '24 13:05 vercel[bot]

Deploy Preview for chipper-cucurucho-7e07f5 ready!

Name Link
Latest commit 490037b9994acb7ae86d11708957588c14bf96c4
Latest deploy log https://app.netlify.com/sites/chipper-cucurucho-7e07f5/deploys/66425e621424d70008a069b8
Deploy Preview https://deploy-preview-81--chipper-cucurucho-7e07f5.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

netlify[bot] avatar May 11 '24 13:05 netlify[bot]

️✅ There are no secrets present in this pull request anymore.

If these secrets were true positive and are still valid, we highly recommend you to revoke them. Once a secret has been leaked into a git repository, you should consider it compromised, even if it was deleted immediately. Find here more information about risks.


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

gitguardian[bot] avatar May 11 '24 13:05 gitguardian[bot]

@piyush-gangrade Send screen recording of running this pr on local and performing otp functionality

JayeshYadav99 avatar May 12 '24 04:05 JayeshYadav99

@JayeshYadav99

https://github.com/TechNodes2-0/ElectiveHub/assets/133166222/c2e70cf5-6e72-4aeb-8a46-ec251426bc13

piyush-gangrade avatar May 12 '24 05:05 piyush-gangrade

@piyush-gangrade Remove otp verification from login only keep it in signup

JayeshYadav99 avatar May 12 '24 06:05 JayeshYadav99

@JayeshYadav99, the following changes have been made

piyush-gangrade avatar May 12 '24 07:05 piyush-gangrade

@piyush-gangrade Hello,

Your contribution looks good to me but there are 2 huge flows

  1. There is loophole that immediate attention. Users should not be able to bypass OTP verification simply not verifying the OPT as signup Page and logining in directly. As you can see in Video.

Keep user authentication data and OTPs in separate collections to prevent bypassing OTP verification during login.

https://github.com/TechNodes2-0/ElectiveHub/assets/93467074/acf663fa-af06-4de0-930d-96020405fc4a

  1. You OPT are stored in plain text in mongodb. So I think it should encrypted but its your take what you think is correct

image

VinayakVispute avatar May 13 '24 11:05 VinayakVispute

ok, I'll fix this issue and update

piyush-gangrade avatar May 13 '24 14:05 piyush-gangrade

Changes:

Additions:

  1. Added server/Models/OtpModel.js to save email, signature, publicKey, and createdAt.
  2. Added server/util/encrypt.js to generate privateKey and publicKey so that we can create a signature of data using privateKey and verify it using publicKey.

Updates:

  1. Updated Signup.jsx so that it can send an OTP and provide inputData to VerifyOTP.jsx with the help of the navigate state and location state.
  2. Updated the sendOtp function of AuthController.js to create an OTP document, save email, signature, and publicKey, and send an OTP to the given email.
  3. Updated VerifyOTP.jsx so that after submitting the OTP, it sends a request to the 'signup' API route with inputData and OTP.
  4. Updated the signup function of AuthController.js so that it first checks if the OTP is valid. If the OTP is valid, it allows the creation of a User and sends back a token

https://github.com/TechNodes2-0/ElectiveHub/assets/133166222/e8ab4712-c12c-4fe4-b163-5ee9ee520020

piyush-gangrade avatar May 13 '24 19:05 piyush-gangrade

@piyush-gangrade Cool , Since my exams are going on, So I was unable to do but I will make sure to give you update today.

VinayakVispute avatar May 15 '24 14:05 VinayakVispute

Thank you! Could you also please add assignees and labels

piyush-gangrade avatar May 15 '24 15:05 piyush-gangrade