{"id":954,"date":"2026-11-27T00:35:59","date_gmt":"2026-11-26T16:35:59","guid":{"rendered":"https:\/\/skyllyf.cc\/?p=954"},"modified":"2026-11-27T00:35:59","modified_gmt":"2026-11-26T16:35:59","slug":"otp%e6%95%b0%e7%9b%be%e5%a4%9a%e5%9b%a0%e5%ad%90%e5%ae%89%e5%85%a8%e8%ae%a4%e8%af%81%e9%85%8d%e7%bd%ae%e5%92%8c%e5%ae%89%e5%85%a8%e6%80%a7%e5%88%86%e6%9e%90","status":"publish","type":"post","link":"https:\/\/skyllyf.cc\/?p=954","title":{"rendered":"OTP\u6570\u76fe\u591a\u56e0\u5b50\u5b89\u5168\u8ba4\u8bc1\u914d\u7f6e\u548c\u5b89\u5168\u6027\u5206\u6790"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u7ba1\u7406\u540e\u53f0\u53ea\u9760\u4e00\u628a\u9759\u6001\u5bc6\u94a5\u5b88\u95e8\uff0c\u5c31\u50cf\u7ed9\u4fdd\u9669\u7bb1\u914d\u4e86\u4e00\u6839\u667e\u8863\u7ef3\u2014\u2014\u5bc6\u94a5\u4e00\u65e6\u6cc4\u9732\uff08\u65e5\u5fd7\u3001\u6d4f\u89c8\u5668\u5386\u53f2\u3001\u793e\u5de5\u3001\u66b4\u529b\u679a\u4e3e\uff09\uff0c\u6574\u4e2a\u540e\u53f0\u7b49\u4e8e\u88f8\u5954\u3002\u7ed9\u767b\u5f55\u6d41\u7a0b\u52a0\u4e0a <strong>TOTP \u52a8\u6001\u7801<\/strong>\uff08\u65f6\u95f4\u578b\u4e00\u6b21\u6027\u5bc6\u7801\uff09\uff0c\u662f\u6210\u672c\u6700\u4f4e\u3001\u6536\u76ca\u6700\u9ad8\u7684\u4e00\u9053\u52a0\u56fa\uff1a\u4e0d\u9700\u8981\u77ed\u4fe1\u901a\u9053\u3001\u4e0d\u4f9d\u8d56\u786c\u4ef6\u4ee4\u724c\uff0c\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u5c31\u591f\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e00\u3001TOTP \u5230\u5e95\u5728\u7b97\u4ec0\u4e48<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">TOTP \u7531 RFC 6238 \u5b9a\u4e49\uff0c\u6838\u5fc3\u516c\u5f0f\u53ea\u6709\u4e00\u884c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>code = Truncate(HMAC-SHA1(Base32\u89e3\u7801(\u5bc6\u94a5), \u230a\u5f53\u524dUnix\u65f6\u95f4 \/ 30\u230b)) mod 10^6<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u62c6\u5f00\u770b\u4e09\u4e2a\u5173\u952e\u9009\u62e9\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>HMAC-SHA1 \/ 30 \u79d2 \/ 6 \u4f4d<\/strong>\uff1a\u8fd9\u662f\u4e8b\u5b9e\u4e0a\u7684\u6807\u51c6\u53c2\u6570\u7ec4\uff0c\u817e\u8bafOTP\u6570\u76fe\u3001Google Authenticator\u3001Microsoft Authenticator \u5168\u90e8\u517c\u5bb9\u3002SHA1 \u867d\u7136\u5df2\u4e0d\u5efa\u8bae\u7528\u4e8e\u7b7e\u540d\/\u8bc1\u4e66\uff0c\u4f46\u5728 TOTP \u573a\u666f\u4e0b\u5b83\u4f5c\u4e3a HMAC \u4f7f\u7528\uff0c\u4e14\u5bc6\u94a5\u662f 20 \u5b57\u8282\u9ad8\u71b5\u968f\u673a\u6570\u3001\u52a8\u6001\u7801 30 \u79d2\u5c31\u6362\uff0c\u76ee\u524d\u4e0d\u5b58\u5728\u73b0\u5b9e\u7684\u653b\u51fb\u8def\u5f84\uff08\u4e0b\u6587\u5b89\u5168\u5206\u6790\u8be6\u8ff0\uff09\u3002<\/li>\n\n\n\n<li><strong>\u00b11 \u4e2a\u65f6\u95f4\u7a97\u7684\u5bb9\u5fcd\u5ea6<\/strong>\uff1a\u6821\u9a8c\u65f6\u540c\u65f6\u6bd4\u5bf9 <code>\u5f53\u524d\u7a97 - 1 \/ \u5f53\u524d\u7a97 \/ \u5f53\u524d\u7a97 + 1<\/code> \u4e09\u7ec4\u503c\uff08\u00b130 \u79d2\uff09\uff0c\u89e3\u51b3\u624b\u673a\u65f6\u949f\u5fae\u5c0f\u504f\u5dee\u5bfc\u81f4\u7684&#8221;\u6c38\u8fdc\u5bf9\u4e0d\u4e0a&#8221;\u3002\u4e0d\u5efa\u8bae\u518d\u653e\u5927\u7a97\u53e3\uff0c\u6bcf\u591a\u5bb9\u5fcd\u4e00\u7a97\u5c31\u591a\u4e00\u500d\u7684\u7206\u7834\u9762\u3002<\/li>\n\n\n\n<li><strong>\u5bc6\u94a5\u751f\u6210<\/strong>\uff1a\u7528 CSPRNG \u7684 <code>random_bytes(20)<\/code> \u751f\u6210 160 \u4f4d\u71b5\uff0cBase32 \u7f16\u7801\u540e\u6070\u597d 32 \u4f4d\u5b57\u7b26\uff0c\u624b\u5de5\u8f93\u5165\u957f\u5ea6\u9002\u4e2d\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u6700\u7ec8\u767b\u5f55\u6a21\u578b\u662f\u4e24\u5c42\u56e0\u5b50\uff1a<strong>\u7ba1\u7406\u5bc6\u94a5\uff08Argon2id \u54c8\u5e0c\u5b58\u50a8\uff09+ 6 \u4f4d\u52a8\u6001\u7801<\/strong>\uff0c\u53e6\u6709 8 \u4e2a\u4e00\u6b21\u6027\u6062\u590d\u7801\u515c\u5e95\u624b\u673a\u4e22\u5931\u573a\u666f\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001\u6570\u636e\u8868\u8bbe\u8ba1\uff08MySQL\uff09<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>sql\n-- \u4e24\u6b65\u9a8c\u8bc1\u5bc6\u94a5\uff08\u5355\u884c\uff0cid \u56fa\u5b9a 1\uff09\nCREATE TABLE IF NOT EXISTS `admin_totp` (\n    `id`         TINYINT UNSIGNED NOT NULL DEFAULT 1,\n    `secret`     VARCHAR(64)      NOT NULL,\n    `enabled`    TINYINT          NOT NULL DEFAULT 0,\n    `created_at` BIGINT           NOT NULL,\n    PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;\n\n-- \u4e00\u6b21\u6027\u6062\u590d\u7801\uff08\u624b\u673a\u4e22\u5931\u65f6\u7528\u5b83\u767b\u5f55\/\u5173\u95ed\u4e24\u6b65\u9a8c\u8bc1\uff1b\u7528\u540e\u5373\u5220\uff09\nCREATE TABLE IF NOT EXISTS `admin_recovery_codes` (\n    `code_hash`  CHAR(64) NOT NULL,\n    `created_at` BIGINT   NOT NULL,\n    PRIMARY KEY (`code_hash`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e24\u4e2a\u8bbe\u8ba1\u8981\u70b9\u503c\u5f97\u6ce8\u610f\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u6062\u590d\u7801\u53ea\u5b58 SHA-256 \u54c8\u5e0c<\/strong>\uff0c\u660e\u6587\u4ec5\u5728\u5f00\u542f\u65f6\u4e00\u6b21\u6027\u56de\u663e\u7ed9\u7528\u6237\uff0c\u5e93\u91cc\u6c38\u8fdc\u67e5\u4e0d\u5230\u660e\u6587\uff1b<\/li>\n\n\n\n<li><strong>\u6d88\u8017\u5373 DELETE<\/strong>\uff0c\u6062\u590d\u7801\u7528\u4e00\u6b21\u5c31\u7269\u7406\u5220\u9664\uff0c\u5929\u7136\u9632\u91cd\u653e\u2014\u2014\u4e0d\u5b58\u5728&#8221;\u8fd9\u4e2a\u7801\u8fd8\u80fd\u4e0d\u80fd\u518d\u7528\u4e00\u6b21&#8221;\u7684\u6b67\u4e49\u3002<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u3001PHP \u6838\u5fc3\u4ee3\u7801<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">3.1 Base32 \u7f16\u89e3\u7801\uff08RFC 4648\uff09<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>php\n\n\/*\u57fa\u672c\u601d\u8def\nin 0x03\nstr\u8865\u4f4d 00000011\n\u5207\u5272\u8865\u4f4d 00000 01100\n\u67e5\u8868  0>A   4>D\n\u8f93\u51faAD  *\/\n\n\/** Base32 \u7f16\u7801\uff08RFC 4648\uff0cTOTP \u7528\uff09 *\/\nfunction base32Encode(string $bin): string\n{\n    $map = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';  \/\/\u6392\u9664\u6613\u6df7\u6dc6\u76840 O 1 I 8 B 9 Base32\u5b57\u6bcd\u8868\n    $bits = '';\n    foreach (str_split($bin) as $c) {  \/\/\u4f20\u5165\u53c2\u6570\uff0c\u5f00\u59cb\u62c6\u5b57\u7b26\u91cf\u5316\u5b57\u8282  8\u4f4d\n        $bits .= str_pad(decbin(ord($c)), 8, '0', STR_PAD_LEFT);   \/\/\u8865\u5145\u52308\u4f4d \u586b\u51450\n    }\n    $out = '';\n    foreach (str_split($bits, 5) as $chunk) {  \/\/\u5207\u62105\u4f4d\n        $out .= $map&#91;bindec(str_pad($chunk, 5, '0', STR_PAD_RIGHT))];  \/\/\u8865\u5145\u540e\u9762\u76840\n    }\n    return $out;\n}\n\n\/** Base32 \u89e3\u7801\uff08\u5ffd\u7565\u7a7a\u683c\u4e0e\u975e\u6cd5\u5b57\u7b26\uff09 *\/\nfunction base32Decode(string $s): string\n{\n    $map = array_flip(str_split('ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'));       \/\/\u6392\u9664\u6613\u6df7\u6dc6\u76840 O 1 I 8 B 9 Base32\u5b57\u6bcd\u8868\n    $s = strtoupper(preg_replace('\/&#91;^A-Z2-7]\/i', '', $s) ?? '');  \/\/\u4f20\u5165\u53c2\u6570\u8f6c\u4e49 \u6e05\u6d17\u672a\u5b9a\u4e49\u5b57\u7b26  \u9632\u6b62null\n    $bits = '';  \n    foreach (str_split($s) as $c) {  \/\/\u62c6bit\u91cf\u5316\u5355\u4e2a\u5b57\u7b26\n        if (!isset($map&#91;$c])) {\n            continue;\n        }\n        $bits .= str_pad(decbin($map&#91;$c]), 5, '0', STR_PAD_LEFT);  \/\/\u8865\u5145\u5b57\u8282\u524d\u9762\u76840 \n    }\n    $out = '';   \n    foreach (str_split($bits, 8) as $byte) {  \/\/\u8f93\u51fa\n        if (strlen($byte) &lt; 8) {\n            break;\n        }\n        $out .= chr(bindec($byte));\n    }\n    return $out;\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3.2 TOTP \u751f\u6210\u4e0e\u6821\u9a8c<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>php\n\/** \u8ba1\u7b97 TOTP 6 \u4f4d\u7801\uff08HMAC-SHA1 \/ 30 \u79d2\uff0c\u4e0e\u4e3b\u6d41 Authenticator \u4e00\u81f4\uff09 *\/\nfunction totpCode(string $secret, ?int $ts = null): string\n{\n    $key = base32Decode($secret);\n    if ($key === '') {\n        return '';\n    }\n    $t = (int) floor(($ts ?? time()) \/ 30);\n    $bin = pack('N*', 0, $t);              \/\/ 64 \u4f4d\u5927\u7aef\u65f6\u95f4\u8ba1\u6570\u5668\n    $hm = hash_hmac('sha1', $bin, $key, true);\n    $o = ord($hm&#91;19]) &amp; 0x0f;              \/\/ \u52a8\u6001\u622a\u65ad\u504f\u79fb\n    $v = ((ord($hm&#91;$o]) &amp; 0x7f) &lt;&lt; 24) | (ord($hm&#91;$o + 1]) &lt;&lt; 16) | (ord($hm&#91;$o + 2]) &lt;&lt; 8) | ord($hm&#91;$o + 3]);\n    return str_pad((string) ($v % 1000000), 6, '0', STR_PAD_LEFT);\n}\n\n\/** \u6821\u9a8c TOTP \u7801\uff08\u5bb9\u5fcd\u524d\u540e\u5404 30 \u79d2\u65f6\u949f\u504f\u5dee\uff09 *\/\nfunction totpVerify(string $secret, string $code): bool\n{\n    $code = preg_replace('\/\\D\/', '', $code) ?? '';\n    if (strlen($code) !== 6 || $secret === '') {\n        return false;\n    }\n    $now = time();\n    for ($i = -1; $i &lt;= 1; $i++) {\n        if (hash_equals(totpCode($secret, $now + $i * 30), $code)) {  \/\/30\u79d2\u504f\u79fb\u65f6\u95f4 \u4e0d\u80fd\u5728\u5927\uff0c\u5728\u5927\u5c31\u4f1a\u964d\u4f4e\u9632\u62a4\u6210\u672c\n            return true;\n        }\n    }\n    return false;\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3.3 \u8868\u8bbf\u95ee\u4e0e\u6062\u590d\u7801<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u60f3\u6765\u60f3\u53bb\u8fd9\u4e2a\u8fd8\u662f\u9700\u8981\u505a\uff0c\u9632\u6b62\u786c\u4ef6\u4e22\u5931\u9020\u6210\u6b7b\u9501\u7684\uff0c\u4f46\u5b89\u5168\u6027\u4f1a\u6253\u6298\u6263<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>php\n\/** \u8bfb\u53d6\u4e24\u6b65\u9a8c\u8bc1\u914d\u7f6e\uff08\u65e0\u8bb0\u5f55\u6216\u8868\u7f3a\u5931\u8fd4\u56de null\uff09 *\/\nfunction adminTotpRow(PDO $db): ?array\n{\n    try {\n        $row = $db->query('SELECT secret, enabled FROM admin_totp WHERE id = 1')->fetch(PDO::FETCH_ASSOC);\n        return $row ?: null;\n    } catch (Throwable $e) {\n        return null; \/\/ \u89c6\u4e3a\u672a\u542f\u7528\uff0c\u907f\u514d\u628a\u540e\u53f0\u9501\u6b7b\n    }\n}\n\n\/** \u751f\u6210 8 \u4e2a\u6062\u590d\u7801\uff08\u5f62\u5982 A1B2C-3D4E5\uff0c\u53bb\u6389\u6613\u6df7\u6dc6\u5b57\u7b26\uff09\uff0c\u53ea\u56de\u663e\u4e00\u6b21 *\/\nfunction adminNewRecoveryCodes(PDO $db): array\n{\n    $chars = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789'; \/\/ \u65e0 0\/O\u30011\/I\/L\n    $codes = &#91;];\n    $ins = $db->prepare('INSERT INTO admin_recovery_codes (code_hash, created_at) VALUES (?, ?)');\n    for ($i = 0; $i &lt; 8; $i++) {\n        $raw = '';\n        for ($j = 0; $j &lt; 10; $j++) {\n            $raw .= $chars&#91;random_int(0, strlen($chars) - 1)];\n        }\n        $pretty = substr($raw, 0, 5) . '-' . substr($raw, 5);\n        $codes&#91;] = $pretty;\n        $ins->execute(&#91;hash('sha256', str_replace('-', '', $pretty)), time()]);\n    }\n    return $codes;\n}\n\n\/** \u6d88\u8017\u4e00\u4e2a\u4e00\u6b21\u6027\u6062\u590d\u7801\uff08\u6210\u529f\u5373\u5220\u9664\uff09 *\/\nfunction adminUseRecoveryCode(PDO $db, string $code): bool\n{\n    $code = strtoupper(preg_replace('\/&#91;^A-Za-z0-9]\/', '', $code) ?? '');\n    if (strlen($code) &lt; 8) {\n        return false;\n    }\n    $h = hash('sha256', $code);\n    try {\n        $st = $db->prepare('SELECT 1 FROM admin_recovery_codes WHERE code_hash = ?');\n        $st->execute(&#91;$h]);\n        if (!$st->fetchColumn()) {\n            return false;\n        }\n        $db->prepare('DELETE FROM admin_recovery_codes WHERE code_hash = ?')->execute(&#91;$h]);\n        return true;\n    } catch (Throwable $e) {\n        return false;\n    }\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u56db\u3001API \u7aef\u70b9<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u7aef\u70b9<\/th><th>\u65b9\u6cd5<\/th><th>\u8bf4\u660e<\/th><\/tr><\/thead><tbody><tr><td><code>\/api\/admin\/totp\/status<\/code><\/td><td>GET<\/td><td><code>{enabled, hasSecret}<\/code><\/td><\/tr><tr><td><code>\/api\/admin\/totp\/setup<\/code><\/td><td>POST<\/td><td>\u751f\u6210\uff08\u6216\u91cd\u7f6e\uff09\u5bc6\u94a5\uff0c\u5148<code>enabled=0<\/code>\uff0c\u8fd4\u56de <code>{secret, uri}<\/code><\/td><\/tr><tr><td><code>\/api\/admin\/totp\/enable<\/code><\/td><td>POST<\/td><td>\u63d0\u4ea4\u4e00\u6b21\u52a8\u6001\u7801\u786e\u8ba4\u540e\u5f00\u542f\uff0c\u4e00\u6b21\u6027\u8fd4\u56de 8 \u4e2a\u6062\u590d\u7801<\/td><\/tr><tr><td><code>\/api\/admin\/totp\/disable<\/code><\/td><td>POST<\/td><td>\u5173\u95ed\u9700\u5f53\u524d\u52a8\u6001\u7801\u6216\u4e00\u4e2a\u672a\u7528\u8fc7\u7684\u6062\u590d\u7801<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">setup \u4e0e enable \u7684\u5173\u952e\u5b9e\u73b0\u2014\u2014<strong>\u4e24\u6bb5\u5f0f\u5f00\u542f<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ setup\uff1a\u751f\u6210\u5bc6\u94a5\u4f46\u5148\u4e0d\u542f\u7528 \u2014\u2014 \u7528\u6237\u786e\u8ba4\u4e00\u6b21\u52a8\u6001\u7801\u540e\u624d\u7b97\u5f00\u542f\ncase $route === 'admin\/totp\/setup' &amp;&amp; $method === 'POST': {\n    adminGuard($cfg);\n    $secret = base32Encode(random_bytes(20)); \/\/ 32 \u4f4d Base32\n    $db->prepare('INSERT INTO admin_totp (id, secret, enabled, created_at) VALUES (1, ?, 0, ?)\n                  ON DUPLICATE KEY UPDATE secret = VALUES(secret), enabled = 0, created_at = VALUES(created_at)')\n        ->execute(&#91;$secret, time()]);\n    $label = rawurlencode('\u6211\u7684\u540e\u53f0:admin');\n    $issuer = rawurlencode('example.com');\n    api_ok(&#91;\n        'secret' => $secret,\n        'uri'    => \"otpauth:\/\/totp\/{$label}?secret={$secret}&amp;issuer={$issuer}&amp;period=30&amp;digits=6\",\n    ]);\n}\n\n\/\/ enable\uff1a\u9a8c\u8bc1\u4e00\u6b21\u52a8\u6001\u7801 \u2192 enabled=1 \u2192 \u53d1\u653e\u6062\u590d\u7801\ncase $route === 'admin\/totp\/enable' &amp;&amp; $method === 'POST': {\n    adminGuard($cfg);\n    $t = adminTotpRow($db);\n    $code = (string) (body()&#91;'code'] ?? '');\n    if (!totpVerify((string) $t&#91;'secret'], $code)) {\n        usleep(300000); \/\/ \u51cf\u7f13\u66b4\u529b\u5c1d\u8bd5\n        api_fail(403, '\u52a8\u6001\u7801\u4e0d\u6b63\u786e\uff0c\u8bf7\u786e\u8ba4\u624b\u673a\u65f6\u95f4\u81ea\u52a8\u540c\u6b65\u540e\u91cd\u8bd5');\n    }\n    $db->exec('UPDATE admin_totp SET enabled = 1 WHERE id = 1');\n    $db->exec('DELETE FROM admin_recovery_codes');\n    api_ok(&#91;'codes' => adminNewRecoveryCodes($db)]);\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u767b\u5f55\u5904\u7684\u6574\u5408\u2014\u2014\u5bc6\u94a5\u901a\u8fc7\u540e\u8fd8\u8981\u8fc7\u52a8\u6001\u7801\u8fd9\u4e00\u5173\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>php\n\/\/ \u767b\u5f55\uff1a\u9650\u901f \u2192 \u5bc6\u94a5(Argon2id) \u2192 TOTP\/\u6062\u590d\u7801 \u2192 \u53d1\u65e5\u8f6e\u6362 HMAC \u4ee4\u724c\n$totp = adminTotpRow($db);\nif ($totp !== null &amp;&amp; (int) $totp&#91;'enabled'] === 1) {\n    $code = (string) ($b&#91;'code'] ?? '');\n    if (!totpVerify((string) $totp&#91;'secret'], $code) &amp;&amp; !adminUseRecoveryCode($db, $code)) {\n        adminAudit($db, 'login_fail_totp', 'ip=' . $ip);\n        usleep(400000);\n        api_fail(403, '\u52a8\u6001\u7801\u4e0d\u6b63\u786e\u6216\u5df2\u8fc7\u671f');\n    }\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e94\u3001\u7ed1\u5b9a\u6d41\u7a0b<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u641c\u6570\u76feOTP\uff08\u76ee\u524d\u662f\u514d\u8d39\u7684\uff0c\u4e0d\u662f\u817e\u8baf\u8eab\u4efd\u9a8c\u8bc1\u5668\uff01\uff01\uff09\u2192 \u6dfb\u52a0\u52a8\u6001\u4ee4\u724c \u2192 \u8f93\u5165\u63d0\u4f9b\u7684\u5bc6\u94a5\uff0c\u8d26\u53f7\u5c31\u662f\u8fd9\u4e2a\u4ee4\u724c\u7684\u7528\u9014\uff0c\u53ef\u4ee5\u968f\u4fbf\u586b\u5199\u4e3b\u8981\u7528\u4e8e\u8bc6\u522b\u591a\u4e2a\u4ee4\u724c \u2192 \u5bc6\u94a5\u586b\u540e\u53f0\u663e\u793a\u7684 Base32 \u5bc6\u94a5\uff1b<\/li>\n\n\n\n<li>\u8f93\u5165 App \u663e\u793a\u7684 6 \u4f4d\u52a8\u6001\u7801 \u2192 \u786e\u8ba4\u5f00\u542f \u2192 <strong>\u6284\u4e0b 8 \u4e2a\u6062\u590d\u7801<\/strong>\uff08\u53ea\u663e\u793a\u8fd9\u4e00\u6b21\uff09\u3002<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">\u524d\u7aef\u8981\u6ce8\u610f\u7684\u7ec6\u8282\uff1a\u767b\u5f55\u9875\u52a8\u6001\u7801\u8f93\u5165\u6846\u7528 <code>&lt;input inputmode=\"numeric\" autocomplete=\"one-time-code\" maxlength=\"13\"&gt;<\/code>\uff0c<code>maxlength=13<\/code> \u662f\u4e3a\u4e86\u517c\u5bb9\u6062\u590d\u7801 <code>A1B2C-3D4E5<\/code> \u7684\u683c\u5f0f\uff1b\u5bc6\u94a5\u5c55\u793a\u7528\u7b49\u5bbd\u5b57\u4f53\u52a0 <code>word-break:break-all<\/code>\uff0c\u65b9\u4fbf\u5bf9\u7167\u624b\u5de5\u8f93\u5165\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u516d\u3001\u5b89\u5168\u6027\u5206\u6790<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">TOTP \u9632\u5f97\u4f4f\u4ec0\u4e48\u3001\u9632\u4e0d\u4f4f\u4ec0\u4e48\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u79cd\u9a8c\u8bc1\u65b9\u5f0f\u53ef\u4ee5\u9632\u6b62\u5f31\u53e3\u4ee4\u7684\u6cc4\u9732\uff08\u4e4b\u524d\u5f00\u53d1\u5c0f\u540e\u7aef\u7684\u65f6\u5019\u88ab\u7206\u7834\u8fc7\uff0c\u6240\u4ee5\u8fd9\u79cd\u65b9\u5f0f\u53ef\u4ee5\u6709\u6548\u9632\u6b62\u5bc6\u7801\u6cc4\u9732\u9020\u6210\u7684\u6c38\u4e45\u6027\u5bc6\u7801\u5b89\u5168\u6027\u635f\u5bb3\uff09<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9632\u6b62\u9493\u9c7c\u4e8b\u4ef6\uff08\u52a8\u6001\u7801\u88ab\u9493\u5c31\u6bd4\u8f83\u5371\u9669\uff0c\u53ef\u4ee5\u9002\u5f53\u7f29\u51cf\u65f6\u95f4\u5bbd\u5bb9\u5ea6  \u89c1TOTP\u6821\u9a8c\u7bc7\u7ae0  \u4eb2\u6d4b\u5728\u56fd\u5185\u6388\u65f6\u7a33\u5b9a\u7684\u60c5\u51b5\u4e0b\u53ef\u4ee5\u7f29\u77ed\u523010\u79d2\uff09<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f46\u662f\u8981\u9632\u8303\u5bc6\u94a5\u5e93\u7684\u6cc4\u9732\uff0c\u5bc6\u94a5\u5e93\u6cc4\u9732\u540e\u52a8\u6001\u7801\u53ef\u4ee5\u4f4e\u6210\u672c\u8fdb\u884c\u65f6\u95f4\u6d4b\u7b97\uff0c\u4ece\u800c\u653b\u7834<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u53e6\u5916&#8230;..\u4e3a\u4ec0\u4e48\u8981\u7528SHA1?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u867d\u7136 SHA1 \u4f5c\u4e3a\u54c8\u5e0c\u7b7e\u540d\u5df2\u88ab\u6dd8\u6c70\uff0c\u4f46 TOTP \u573a\u666f\u4e0d\u540c,HMAC-SHA1 \u7684\u5b89\u5168\u6027\u4f9d\u8d56\u7684\u662f HMAC \u7ed3\u6784\u6297\u78b0\u649e\u6027\u800c\u975e SHA1 \u7684\u6297\u78b0\u649e\u672c\u8eab\uff0c\u653b\u51fb\u8005\u65e0\u6cd5\u79bb\u7ebf\u679a\u4e3e\uff08\u5bc6\u94a5 160 \u4f4d\u9ad8\u71b5\uff09\uff0c\u52a0\u4e0a\u52a8\u6001\u7801\u9650\u65f6\u8f6e\u6362\u4e14\u670d\u52a1\u7aef\u672c\u8eab\u6709\u9650\u901f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><strong>\u5199\u5728\u6700\u540e<\/strong><\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">OTP\u65b9\u5f0f\u6709\u5229\u6709\u5f0a\uff0c\u6700\u6015\u914d\u7f6e\u5931\u8bef\u5bfc\u81f4\u81ea\u5df1\u88ab\u9501\u5728\u95e8\u5916\uff0c\u6700\u597d\u5728\u84dd\u9c7c\u6c99\u7bb1\uff08Docker\uff09\u4e2d\u6d4b\u8bd5\u540e\u4f7f\u7528\uff0c\u4ee5\u514d\u5c0f\u7ad9\u540e\u53f0\u6b7b\u9501 &#8211; -\uff01<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7ba1\u7406\u540e\u53f0\u53ea\u9760\u4e00\u628a\u9759\u6001\u5bc6\u94a5\u5b88\u95e8\uff0c\u5c31\u50cf\u7ed9\u4fdd\u9669\u7bb1\u914d\u4e86\u4e00\u6839\u667e\u8863\u7ef3\u2014\u2014\u5bc6\u94a5\u4e00\u65e6\u6cc4\u9732\uff08\u65e5\u5fd7\u3001\u6d4f\u89c8\u5668\u5386\u53f2\u3001\u793e\u5de5\u3001\u66b4\u529b\u679a\u4e3e\uff09\uff0c\u6574\u4e2a\u540e\u53f0\u7b49\u4e8e\u88f8\u5954\u3002\u7ed9\u767b\u5f55\u6d41\u7a0b\u52a0\u4e0a TOTP \u52a8\u6001\u7801\uff08\u65f6\u95f4\u578b\u4e00\u6b21\u6027\u5bc6\u7801\uff09\uff0c\u662f\u6210\u672c\u6700\u4f4e\u3001\u6536\u76ca\u6700&#8230;<\/p>\n","protected":false},"author":1,"featured_media":955,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[42,46,45,43],"class_list":["post-954","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-web","tag-otp","tag-php","tag-45","tag-43"],"_links":{"self":[{"href":"https:\/\/skyllyf.cc\/index.php?rest_route=\/wp\/v2\/posts\/954","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/skyllyf.cc\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/skyllyf.cc\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/skyllyf.cc\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/skyllyf.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=954"}],"version-history":[{"count":1,"href":"https:\/\/skyllyf.cc\/index.php?rest_route=\/wp\/v2\/posts\/954\/revisions"}],"predecessor-version":[{"id":956,"href":"https:\/\/skyllyf.cc\/index.php?rest_route=\/wp\/v2\/posts\/954\/revisions\/956"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/skyllyf.cc\/index.php?rest_route=\/wp\/v2\/media\/955"}],"wp:attachment":[{"href":"https:\/\/skyllyf.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=954"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/skyllyf.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=954"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/skyllyf.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=954"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}