feat: 后端用户密码哈希存储
This commit is contained in:
1 parent
6e0a416422
commit
315916d027
10 files changed
+50
-31
No files matched your search
@@ -1,4 +1,3 @@
|
||||
// import { defineEventHandler, readBody, createError } from 'h3';
|
||||
import bcrypt from 'bcryptjs';
|
||||
import BetterSqlite3 from 'better-sqlite3';
|
||||
|
||||
@@ -10,9 +9,10 @@ export default defineEventHandler(async (event) => {
|
||||
// 查询用户
|
||||
const userDB = BetterSqlite3('./userData/db/user.db');
|
||||
const user: any = userDB.prepare('SELECT * FROM user WHERE username = ?').get(username);
|
||||
if (!user || password !== user.password) {
|
||||
const authRes = await authUser(username, password);
|
||||
if(!authRes){
|
||||
userDB.close();
|
||||
throw createError({ statusCode: 401, statusMessage: 'Invalid username or password' });
|
||||
throw createError({ statusCode: 401, statusMessage: 'Username or password is incorrect' });
|
||||
}
|
||||
|
||||
// 更新最后登录时间
|
||||
|
||||
Reference in new issue
Block a user