I'm making a Actix-web/Rust web-application where users are solely allowed to register and login with their mobile phone number. The login-screen consists of one input asking for the phone number. If a user with that phone number already exists in the database he gets redirected to the authentication-page, otherwise to the registration page.
The authentication-page has only one input asking for a authentication-code. This code is sent to the user by SMS as soon as he wants to login.
I want to verify that the system I am using is secure and valid.
This is a simplified version of the relevant MySQL tables:
Steps of authentication:
- The user inputs his phone number in the login-screen.
- System checks and sees that a user with this phone number exists.
- In the table
UserAuthenticationRequest
we insert:- The ID of the User trying to authenticate.
- A random generated number of 6 ciphers (hashed).
- The timestamp of the insert.
- The number of guessing attempts for this specific authentication request, default 0.
- Random generated number is sent to the phone number of the user through SMS.
- User is redirected to the authentication-page where he needs to insert received number.
- If the hashes of the given number and the number in the table
UserAuthenticationRequest
match, the user is authenticated. - If not, the column
attempts
increases with one.
Extra info:
- In the table
UserAuthenticationRequest
the columnuser_id
is unique. So for each user there can only be one authentication at the same time, - A MySQL event will be configured to delete all rows older then 15 minutes.
- If an authentication has more then 3 attempts the row gets deleted and a new code must be requested.
- The authentication is session-bound so the generated number must be inputted in the same browser as in which the request was sent.
Is this a safe system to authenticate users?