Search code examples
authenticationuser-registration

user database with OTP verified: How to keep only users whose OTP is verfied


I am creating an user registration and login.

I have an application where user have to confirm OTP sent to his email inorder to complete the registration.

I have save the user registration data in the database and verify the OTP during registration.

But if someone leaves inbetween during entering the OTP, that data will still be stored in the database.

Is there a way to clean those entries who didnt enter the OTP.

How to keep only users whose OTP is verfied when some users may leave in the middle without verifying the OTP


Solution

  • The usual method is to set a maximum time until the registration code (you call it OTP) is valid.

    So either

    • store registration time and check whether current time is within a fixed time period starting at registration time or
    • directly store the end of validity period.