Answer the question
In order to leave comments, you need to log in
How does one time password work on TOTP?
There was a task to make authentication by SMS. For these purposes, I decided to use a time-based one-time password (TOTP) and a PHP library - Spomky-Labs / otphp. While I'm playing with it, in order to understand the essence of the work, I wrote a code for testing:
$otp = TOTP::create('ggg');
echo $otp->verify($_GET['code']);
echo $otp->now();
echo '
<form action="index.php" method="GET">
<input name="code" type="text">
</form>
';
Answer the question
In order to leave comments, you need to log in
Answers to questions 1 and 2 are correct . Answers to questions
3 are not. If one-time TOTP passwords are used, it is assumed that the user has a mobile application that gives him keys and shows how long this password will be valid.
For SMS authentication, TOTP is not the best option
If you need an understanding of the algorithm https://habr.com/ru/post/154229/
That is, if the user requests a password at 13:59, he will not have 30 seconds to enter, but only one second. How can this be dealt with?check not only the password for the current time, but also for 30 seconds ago, so that the previous one works, but be careful, there are (albeit far-fetched) cases when the password time is up to date and the code from the past cannot be allowed ..
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question