Files
yunrui_asset/frontend/src/utils/crypto.js
T
zhang1106 9e6a3da888 feat: 添加请求参数验证中间件和设计令牌Hook
feat(validation): 为机房、机柜和设备路由添加Joi验证中间件

feat(hooks): 创建useDesignTokens Hook集中管理主题配置

feat(models): 为耗材模型添加乐观锁version字段和updatedAt索引

feat(3d): 增强3D场景和设备模型视觉效果与交互

refactor: 移除数据备份相关功能并优化代码结构

fix: 修复前端安全日志和密码加密工具

chore: 更新依赖并添加axios和joi库

docs: 更新注释和文档说明

style: 改进代码格式和命名一致性
2026-01-29 16:53:29 +08:00

28 lines
888 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 前端密码加密工具
* 注意:这只是增加一层保护,真正的安全需要 HTTPS
*/
/**
* 使用 SHA-256 对密码进行哈希
* @param {string} password - 明文密码
* @returns {Promise<string>} - 返回十六进制哈希值
*/
export async function hashPassword(password) {
const encoder = new TextEncoder();
const data = encoder.encode(password);
const hashBuffer = await crypto.subtle.digest('SHA-256', data);
const hashArray = Array.from(new Uint8Array(hashBuffer));
return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
}
/**
* 为登录请求准备密码(双重哈希:SHA-256 + 服务器 bcrypt
* @param {string} password - 明文密码
* @returns {Promise<string>} - 哈希后的密码
*/
export async function preparePassword(password) {
if (!password) return password;
return await hashPassword(password);
}