Djangootp:我应该在生成hotp令牌时增加计数器吗?

2024-04-26 02:35:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我用django otp生成hotp, 我还没有找到正确生成hotp令牌的文档

因此,我阅读了HOTPDevice模型类中的verify_token方法,了解了如何验证令牌

if hotp(key, counter, self.digits) == token:
    verified = True
    self.counter = counter + 1
    self.save()

从上面我知道我可以使用hotp函数创建令牌。你知道吗

然后我使用hotp函数来生成令牌,但是我注意到它在未确认时重复返回相同的令牌。所以在生成它的时候我应该增加counter吗?你知道吗

资料来源:HOTPDevice source from django-otp


Tags: django方法key函数文档模型selftoken
1条回答
网友
1楼 · 发布于 2024-04-26 02:35:18

所以我找到了RFC 4226 - HOTP的引语

The HOTP client (hardware or software token) increments its counter and then calculates the next HOTP value HOTP client

因此,我应该首先增加counter,将其保存到对象,然后返回生成的令牌

相关问题 更多 >