You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
776 B
30 lines
776 B
import bcrypt from "bcryptjs";
|
|
|
|
export const EMBED_PASSWORD_MIN = 6;
|
|
export const EMBED_PASSWORD_MAX = 64;
|
|
export const DEFAULT_EMBED_PASSWORD = "123456";
|
|
|
|
export function validateEmbedPassword(password: string): string | null {
|
|
if (!password) {
|
|
return "密码不能为空";
|
|
}
|
|
if (password.length < EMBED_PASSWORD_MIN) {
|
|
return `密码至少 ${EMBED_PASSWORD_MIN} 位`;
|
|
}
|
|
if (password.length > EMBED_PASSWORD_MAX) {
|
|
return `密码不能超过 ${EMBED_PASSWORD_MAX} 位`;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
export async function hashEmbedPassword(password: string): Promise<string> {
|
|
return bcrypt.hash(password, 10);
|
|
}
|
|
|
|
export async function compareEmbedPassword(
|
|
password: string,
|
|
hash: string,
|
|
): Promise<boolean> {
|
|
return bcrypt.compare(password, hash);
|
|
}
|