Communitygithub.com

YepAPI/认证安全技能

认证安全 — bcrypt/argon2 哈希、暴力破解防护、安全密码重置。

认证安全技能 是什么?

该技能专注于实现现代应用程序中的认证安全,提供密码哈希、暴力破解防护和安全密码重置的全面指南。它强制使用 bcrypt(成本因子 12 以上)或 argon2id 进行密码哈希,明确禁止使用纯文本、SHA/MD5 或可逆加密。技能定义了严格的速率限制规则:每个 IP 每分钟最多 5 次登录尝试,每个账户每小时最多 10 次。通过指数级锁定时间(1秒、2秒、4秒、8秒...)并在 10 次失败后硬锁定 15 分钟来应对暴力破解。密码重置令牌必须是加密安全的随机令牌,一次性使用,并且在一小时内过期。错误消息保持通用性,例如“邮箱或密码无效”,绝不透露哪个字段有误。技能还要求密码最小长度为 8 个字符,并通过 HaveIBeenPwned API 检查是否出现在已泄露密码列表中。支持所有主流框架和后端环境,基于 TypeScript 示例进行说明。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/YepAPI/skills/tree/HEAD/skills/auth-security

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

认证安全

规则

  • 使用 bcrypt(成本因子 12 以上)或 argon2id 对密码进行哈希处理 — 绝不存储明文或使用 SHA/MD5
  • 对登录端点进行速率限制:每个 IP 每分钟最多 5 次尝试,每个账户每小时最多 10 次
  • 实施指数级锁定:失败尝试后 1 秒、2 秒、4 秒、8 秒... 在 10 次失败后硬锁定 15 分钟
  • 密码重置令牌:加密安全的随机令牌,一次性使用,最迟在 1 小时内过期
  • 返回通用错误:“邮箱或密码无效” — 绝不透露哪个字段有误
  • 强制执行密码最小长度为 8 个字符,检查是否出现在已泄露密码列表中(HaveIBeenPwned API)
import bcrypt from "bcrypt";

// 注册时哈希密码
const hash = await bcrypt.hash(password, 12);

// 登录时验证密码
const valid = await bcrypt.compare(password, storedHash);
if (!valid) {
  await incrementFailedAttempts(userId);
  return res.status(401).json({ error: "Invalid email or password" });
}
await resetFailedAttempts(userId);
// 暴力破解锁定检查
async function checkLockout(userId: string) {
  const attempts = await getFailedAttempts(userId);
  if (attempts.count >= 10) {
    const lockoutEnd = attempts.lastAttempt + 15 * 60 * 1000;
    if (Date.now() < lockoutEnd) throw new Error("Account temporarily locked");
  }
}

避免

  • 以明文、base64 或可逆加密方式存储密码
  • 使用 SHA-256 处理密码 — 它速度很快,意味着容易遭受暴力破解
  • 在登录或密码重置时泄露邮箱是否存在
  • 密码重置链接永不过期或可重复使用
  • 允许来自单个 IP 的无限登录尝试

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

YepAPI/skills

WCAG 2.1 AA — semantic HTML, keyboard navigation, screen readers.

YepAPI/skills

Experiment setup, variant splitting, statistical significance, and feature flag integration.

YepAPI/skills

CRUD generators, data tables, user management, role-based access, and bulk operations.

YepAPI/skills

Monitor what ChatGPT and Gemini say about your brand using YepAPI.

YepAPI/skills

Queue workers with BullMQ/Inngest/Trigger.dev, job retries, dead letter queues, concurrency.

YepAPI/skills

Commander.js, interactive prompts with Clack, spinners, colors, config files, exit codes, and npm publishing.

YepAPI/skills

cmdk integration, Cmd+K trigger, fuzzy search, grouped actions, keyboard navigation, and dynamic action registration.

YepAPI/skills

Content planning with trend and sentiment data from YepAPI.

YepAPI/skills

Content calendar, keyword-driven planning, and content briefs.

YepAPI/skills

Theme switching with CSS variables, system preference detection, next-themes, and persistence.

YepAPI/skills

Threaded comments, @mentions, reactions, moderation queue, optimistic UI, and cursor pagination.

YepAPI/skills

Competitive analysis between domains using YepAPI.

YepAPI/skills

Layout grids, KPI cards, data tables with sorting/filtering, sidebar navigation, and responsive breakpoints.

YepAPI/skills

Data encryption — TLS everywhere, AES-256-GCM for PII, bcrypt passwords, encrypted backups.

YepAPI/skills

Chart patterns with Recharts/Nivo/D3, responsive containers, color scales, and accessibility.

YepAPI/skills

Drizzle schema definition, push vs migrate, type-safe queries, relations, transactions, and prepared statements.

YepAPI/skills

Upload handling, resize/compress, CDN delivery, blur placeholders, and next/image patterns.

YepAPI/skills

Local business and Google Maps research using YepAPI.

YepAPI/skills

Cursor-based pagination, IntersectionObserver, virtualized lists with @tanstack/react-virtual, and scroll position restoration.

YepAPI/skills

Chat UI components, streaming responses with AI SDK, context window management, and RAG patterns.

相关技能