fix(auth): 修复设置支付密码时报错的问题
支付密码是6位纯数字,但 setTradePassword 调用了 Password.create() 走了登录密码的格式验证(要求≥8位+字母+数字),导致必然抛出异常。 新增 Password.createWithoutValidation() 方法,仅做 bcrypt hash 不走格式验证。支付密码的格式验证由 trade-password.service.ts 独立处理。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
4a1bf3aafe
commit
16da1d20f0
|
|
@ -251,10 +251,10 @@ export class UserAggregate {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置支付密码
|
* 设置支付密码(6位数字,使用独立的哈希逻辑,不走登录密码的格式验证)
|
||||||
*/
|
*/
|
||||||
async setTradePassword(newPlainPassword: string): Promise<void> {
|
async setTradePassword(newPlainPassword: string): Promise<void> {
|
||||||
const password = await Password.create(newPlainPassword);
|
const password = await Password.createWithoutValidation(newPlainPassword);
|
||||||
this._tradePasswordHash = password.hash;
|
this._tradePasswordHash = password.hash;
|
||||||
this._updatedAt = new Date();
|
this._updatedAt = new Date();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,14 @@ export class Password {
|
||||||
return new Password(hash);
|
return new Password(hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从明文密码创建(跳过格式验证,用于支付密码等有独立验证规则的场景)
|
||||||
|
*/
|
||||||
|
static async createWithoutValidation(plainPassword: string): Promise<Password> {
|
||||||
|
const hash = await bcrypt.hash(plainPassword, Password.SALT_ROUNDS);
|
||||||
|
return new Password(hash);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从已加密的 hash 重建
|
* 从已加密的 hash 重建
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue