feat(认证): 添加默认密码作为备用方案
当密码文件不存在或读取失败时,使用默认密码作为备用方案,提高系统的容错能力
This commit is contained in:
parent
8a1ccb9877
commit
8bfa7e1dbf
1 changed files with 13 additions and 2 deletions
|
|
@ -200,16 +200,27 @@ async function cleanupExpiredTokens() {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认密码(当pwd文件不存在时使用)
|
||||
*/
|
||||
const DEFAULT_PASSWORD = 'admin123';
|
||||
|
||||
/**
|
||||
* 读取密码文件内容
|
||||
*/
|
||||
async function readPasswordFile() {
|
||||
try {
|
||||
const password = await fs.readFile(path.join(process.cwd(), 'configs', 'pwd'), 'utf8');
|
||||
const pwdFilePath = path.join(process.cwd(), 'configs', 'pwd');
|
||||
if (!existsSync(pwdFilePath)) {
|
||||
console.log('[Auth] 密码文件不存在,使用默认密码');
|
||||
return DEFAULT_PASSWORD;
|
||||
}
|
||||
const password = await fs.readFile(pwdFilePath, 'utf8');
|
||||
return password.trim();
|
||||
} catch (error) {
|
||||
console.error('读取密码文件失败:', error);
|
||||
return null;
|
||||
console.log('[Auth] 读取密码文件失败,使用默认密码');
|
||||
return DEFAULT_PASSWORD;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue