3

One-Time Password

 2 years ago
source link: https://fann.im/blog/2015/05/27/one-time-password/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

One-Time Password

May 27, 2015

两步验证是基于 HOTP/TOTP 算法的验证方案,在登录的时候除了密码,也需要提供动态数字(一般是六位数)验证。其中 HOTP(HMAC-based One-time Password) 是计数器令牌,一定次数内有效,TOTP(Time-based One-time Password) 只是一定时间内有效。

可以用两步验证的思路做一个没有固定密码,只有动态密码的注册登录流程:

  1. 发送用户邮箱到服务器,检查邮箱对应的用户是否存在。
  2. 用户不存在,新建用户,根据邮箱生成密钥并保存,引导用户通过 Google Authenticator/Authy 等保存密钥,可以验证一次确保密钥成功保存,注册成功并登录。
  3. 用户存在,提示用户填写 Google Authenticator/Authy 生成的验证码,服务器验证是否有效。
  4. 如果用户密钥忘记或被盗,可以通过邮件进行验证,然后重新设置密钥并保存。

整个流程和手机短信验证类似,不同的是通过软件保存密钥并生成验证码,而不是手机短信获取。其中 根据邮箱生成密钥是关键,如果算法过于简单,别人知道邮箱后很容易就能猜出密钥,进而得到验证码。初步想到的算法:邮箱+时间戳,SHA/MD5/AES/RC4 等加密计算。

当然这套验证的前提条件是没有物理接触:如果服务被攻陷或拿到密钥算法,整个就完蛋。如果用户手机被拿到,自然就能随便登录。

Was this page helpful?


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK