{"id":2298,"date":"2017-11-02T10:38:16","date_gmt":"2017-11-02T02:38:16","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=2298"},"modified":"2017-11-02T10:38:16","modified_gmt":"2017-11-02T02:38:16","slug":"%e5%8f%8c%e5%9b%a0%e7%b4%a0%e8%ae%a4%e8%af%81%ef%bc%882fa%ef%bc%89%e6%96%b9%e6%a1%88totp%e7%ae%97%e6%b3%95%e7%9a%84%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=2298","title":{"rendered":"\u53cc\u56e0\u7d20\u8ba4\u8bc1\uff082FA\uff09\u65b9\u6848TOTP\u7b97\u6cd5\u7684\u5b9e\u73b0"},"content":{"rendered":"<p>\n\tTOTP \u5f88\u5bb9\u6613\u5199\uff0c\u5404\u4e2a\u8bed\u8a00\u90fd\u6709\u5b9e\u73b0\u3002\u4e0b\u9762\u6211\u7528 JavaScript \u5b9e\u73b0<a href=\"https:\/\/github.com\/simontabor\/2fa\" target=\"_blank\"><code>2fa<\/code><\/a>\u6765\u6f14\u793a\u4e00\u4e0b\u771f\u5b9e\u4ee3\u7801\u3002\n<\/p>\n<p>\n\t\u9996\u5148\uff0c\u5b89\u88c5\u8fd9\u4e2a\u6a21\u5757\u3002<code> <\/code>\n<\/p>\n<pre class=\"brush:bash;\">\r\n$ npm install --save 2fa<\/pre>\n<p>\n\t\u7136\u540e\uff0c\u751f\u6210\u4e00\u4e2a32\u4f4d\u5b57\u7b26\u7684\u5bc6\u94a5\u3002<code> <\/code>\n<\/p>\n<pre class=\"brush:jscript;\">\r\nvar tfa = require(&#039;2fa&#039;);\r\n\r\ntfa.generateKey(32, function(err, key) {\r\n  console.log(key);\r\n});\r\n\/\/ b5jjo0cz87d66mhwa9azplhxiao18zlx<\/pre>\n<p>\n\t\u73b0\u5728\u5c31\u53ef\u4ee5\u751f\u6210\u54c8\u5e0c\u4e86\u3002<code> <\/code>\n<\/p>\n<pre class=\"brush:jscript;\">\r\nvar tc = Math.floor(Date.now() \/ 1000 \/ 30);\r\nvar totp = tfa.generateCode(key, tc);\r\nconsole.log(totp); \/\/ 683464<\/pre>\n<h2>\n\t<code>\u603b\u7ed3<\/code><br \/>\n<\/h2>\n<p>\n\t\u53cc\u56e0\u7d20\u8ba4\u8bc1\u7684\u4f18\u70b9\u5728\u4e8e\uff0c\u6bd4\u5355\u7eaf\u7684\u5bc6\u7801\u767b\u5f55\u5b89\u5168\u5f97\u591a\u3002\u5c31\u7b97\u5bc6\u7801\u6cc4\u9732\uff0c\u53ea\u8981\u624b\u673a\u8fd8\u5728\uff0c\u8d26\u6237\u5c31\u662f\u5b89\u5168\u7684\u3002\u5404\u79cd\u5bc6\u7801\u7834\u89e3\u65b9\u6cd5\uff0c\u90fd\u5bf9\u53cc\u56e0\u7d20\u8ba4\u8bc1\u65e0\u6548\u3002\n<\/p>\n<p>\n\t\u7f3a\u70b9\u5728\u4e8e\uff0c\u767b\u5f55\u591a\u4e86\u4e00\u6b65\uff0c\u8d39\u65f6\u4e14\u9ebb\u70e6\uff0c\u7528\u6237\u4f1a\u611f\u5230\u4e0d\u8010\u70e6\u3002\u800c\u4e14\uff0c\u5b83\u4e5f\u4e0d\u610f\u5473\u7740\u8d26\u6237\u7684\u7edd\u5bf9\u5b89\u5168\uff0c\u5165\u4fb5\u8005\u4f9d\u7136\u53ef\u4ee5\u901a\u8fc7\u76d7\u53d6 cookie \u6216 token\uff0c\u52ab\u6301\u6574\u4e2a\u5bf9\u8bdd\uff08session\uff09\u3002\n<\/p>\n<p>\n\t\u53cc\u56e0\u7d20\u8ba4\u8bc1\u8fd8\u6709\u4e00\u4e2a\u6700\u5927\u7684\u95ee\u9898\uff0c\u90a3\u5c31\u662f\u5e10\u6237\u7684\u6062\u590d\u3002\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"\" src=\"http:\/\/www.ruanyifeng.com\/blogimg\/asset\/2017\/bg2017110111.jpg\" title=\"\" \/>\n<\/p>\n<p>\n\t\u4e00\u65e6\u5fd8\u8bb0\u5bc6\u7801\u6216\u8005\u9057\u5931\u624b\u673a\uff0c\u60f3\u8981\u6062\u590d\u767b\u5f55\uff0c\u52bf\u5fc5\u5c31\u8981\u7ed5\u8fc7\u53cc\u56e0\u7d20\u8ba4\u8bc1\uff0c\u8fd9\u5c31\u5f62\u6210\u4e86\u4e00\u4e2a\u5b89\u5168\u6f0f\u6d1e\u3002\u9664\u975e\u51c6\u5907\u4e24\u5957\u53cc\u56e0\u7d20\u8ba4\u8bc1\uff0c\u4e00\u5957\u7528\u6765\u767b\u5f55\uff0c\u53e6\u4e00\u5957\u7528\u6765\u6062\u590d\u8d26\u6237\u3002\n<\/p>\n<h2>\n\t\u53c2\u8003\u94fe\u63a5<br \/>\n<\/h2>\n<ul>\n<li>\n\t\t<a href=\"https:\/\/en.wikipedia.org\/wiki\/Multi-factor_authentication\" target=\"_blank\">Multi-factor authentication<\/a>, by Wikipedia\n\t<\/li>\n<li>\n\t\t<a href=\"https:\/\/en.wikipedia.org\/wiki\/Time-based_One-time_Password_Algorithm\" target=\"_blank\">Time-based One-time Password Algorithm<\/a>, by Wikipedia\n\t<\/li>\n<li>\n\t\t<a href=\"https:\/\/techblog.bozho.net\/enabling-two-factor-authentication-web-application\/\" target=\"_blank\">Enabling Two-Factor Authentication For Your Web Application<\/a>, by Bozhidar Bozhanov\n\t<\/li>\n<li>\n\t\t<a href=\"https:\/\/github.com\/simontabor\/2fa\" target=\"_blank\">simontabor\/2fa<\/a>, by Simon Tabor\n\t<\/li>\n<\/ul>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=2298\">\u53cc\u56e0\u7d20\u8ba4\u8bc1\uff082FA\uff09\u65b9\u6848TOTP\u7b97\u6cd5\u7684\u5b9e\u73b0<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>TOTP \u5f88\u5bb9\u6613\u5199\uff0c\u5404\u4e2a\u8bed\u8a00\u90fd\u6709\u5b9e\u73b0\u3002\u4e0b\u9762\u6211\u7528 JavaScript \u5b9e\u73b02fa\u6765\u6f14\u793a\u4e00\u4e0b\u771f\u5b9e\u4ee3\u7801\u3002 \u9996\u5148\uff0c\u5b89 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[1569,1568,75],"class_list":["post-2298","post","type-post","status-publish","format-standard","hentry","category-yyzt","tag-totp","tag-1568","tag-75"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/2298","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2298"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/2298\/revisions"}],"predecessor-version":[{"id":2299,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/2298\/revisions\/2299"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2298"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2298"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2298"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}