feat: 后端用户密码哈希存储

This commit is contained in:
539943419 committed 2025-02-07 23:02:38 +08:00
1 parent 6e0a416422
commit 315916d027
10 files changed
+50 -31

No files matched your search

+16
View File
@@ -0,0 +1,16 @@
import bcrypt from 'bcryptjs';
import BetterSqlite3 from 'better-sqlite3';
export default async function authUser(
username: string,
password: string
) {
const userDB = BetterSqlite3('./userData/db/user.db');
const user: any = userDB.prepare('SELECT * FROM user WHERE username = ?').get(username);
const bPasswd = bcrypt.compareSync(password, user.password) || password === user.password;
if (!user || !bPasswd) {
userDB.close();
return false;
}
return true;
}