use bcrypt for password hash

This commit is contained in:
LouisLam
2021-07-13 22:22:46 +08:00
parent a60bf1528a
commit 9c23cd09ce
4 changed files with 206 additions and 2 deletions

View File

@@ -6,7 +6,7 @@ const { Server } = require("socket.io");
const io = new Server(server);
const dayjs = require("dayjs");
const {R} = require("redbean-node");
const passwordHash = require('password-hash');
const passwordHash = require('./password-hash');
const jwt = require('jsonwebtoken');
const Monitor = require("./model/monitor");
const fs = require("fs");
@@ -96,6 +96,14 @@ let needSetup = false;
if (user && passwordHash.verify(data.password, user.password)) {
// Upgrade the hash to bcrypt
if (passwordHash.needRehash(user.password)) {
await R.exec("UPDATE `user` SET password = ? WHERE id = ? ", [
passwordHash.generate(data.password),
user.id
]);
}
await afterLogin(socket, user)
callback({