SCALE — Build Lab

2要素認証(TOTP)

推奨 セキュリティ

パスワード + ワンタイムコード(Google Authenticator 等)で二重ロック。

なぜ必要?

パスワード漏洩しても突破されない。CRM・経理系は必須レベル。

どう実装する?

speakeasy で TOTP secret 生成 → QRコード表示 → 6桁コード検証。

コード例
ts
import speakeasy from 'speakeasy';
import qrcode from 'qrcode';

// セットアップ
const secret = speakeasy.generateSecret({ name: 'SCALE CRM (user@example.com)' });
const qrUrl = await qrcode.toDataURL(secret.otpauth_url!);
// secret.base32 を DB に保存

// ログイン時の検証
const ok = speakeasy.totp.verify({
  secret: userSecret,
  encoding: 'base32',
  token: inputCode,
  window: 1,
});

2要素認証(TOTP)

:LiTarget: 何のために?

パスワード漏洩しても突破されない。CRM・経理系は必須レベル。

:LiSparkle: どう実装する?

speakeasy で TOTP secret 生成 → QRコード表示 → 6桁コード検証。

:LiCode: コード例

import speakeasy from 'speakeasy';
import qrcode from 'qrcode';

// セットアップ
const secret = speakeasy.generateSecret({ name: 'SCALE CRM (user@example.com)' });
const qrUrl = await qrcode.toDataURL(secret.otpauth_url!);
// secret.base32 を DB に保存

// ログイン時の検証
const ok = speakeasy.totp.verify({
  secret: userSecret,
  encoding: 'base32',
  token: inputCode,
  window: 1,
});