From the course: Securing Django Applications

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Confirming SMS code and enabling 2FA

Confirming SMS code and enabling 2FA - Django Tutorial

From the course: Securing Django Applications

Start my 1-month free trial

Confirming SMS code and enabling 2FA

- To confirm and validate the two factor auth code, we need to define a new class method called validate code. So it's a class method, called validate code. And we pass in the user and the code. And we're going to first check if the user is anonymous. And if that is the case, we return False, then we check if there is an existing auth code that matches by matching against the user, and the code that was given. And sorting by the sent on date, so that we are matching against the most recently issued two factor auth code. If existing is None, there is no match then we create an activity log. For this user, where the action is, they entered, an incorrect two factor auth code. And then we return False. And the last case here, is that the authentication code they entered is valid so we're going to delete this auth code so it can't be re-used. And then we're going to create a log for the user. An action is that they…

Contents