mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-09-22 21:09:20 +08:00
Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
4d666f8280 |
@@ -26,7 +26,7 @@ exports.login = async function (username, password) {
|
|||||||
// Upgrade the hash to bcrypt
|
// Upgrade the hash to bcrypt
|
||||||
if (passwordHash.needRehash(user.password)) {
|
if (passwordHash.needRehash(user.password)) {
|
||||||
await R.exec("UPDATE `user` SET password = ? WHERE id = ? ", [
|
await R.exec("UPDATE `user` SET password = ? WHERE id = ? ", [
|
||||||
passwordHash.generate(password),
|
await passwordHash.generate(password),
|
||||||
user.id,
|
user.id,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,4 @@
|
|||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const fsAsync = fs.promises;
|
|
||||||
const { R } = require("redbean-node");
|
const { R } = require("redbean-node");
|
||||||
const { setSetting, setting } = require("./util-server");
|
const { setSetting, setting } = require("./util-server");
|
||||||
const { log, sleep } = require("../src/util");
|
const { log, sleep } = require("../src/util");
|
||||||
@@ -708,12 +707,12 @@ class Database {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the size of the database (SQLite only)
|
* Get the size of the database (SQLite only)
|
||||||
* @returns {Promise<number>} Size of database
|
* @returns {number} Size of database
|
||||||
*/
|
*/
|
||||||
static async getSize() {
|
static getSize() {
|
||||||
if (Database.dbConfig.type === "sqlite") {
|
if (Database.dbConfig.type === "sqlite") {
|
||||||
log.debug("db", "Database.getSize()");
|
log.debug("db", "Database.getSize()");
|
||||||
let stats = await fsAsync.stat(Database.sqlitePath);
|
let stats = fs.statSync(Database.sqlitePath);
|
||||||
log.debug("db", stats);
|
log.debug("db", stats);
|
||||||
return stats.size;
|
return stats.size;
|
||||||
}
|
}
|
||||||
|
@@ -14,7 +14,7 @@ class User extends BeanModel {
|
|||||||
*/
|
*/
|
||||||
static async resetPassword(userID, newPassword) {
|
static async resetPassword(userID, newPassword) {
|
||||||
await R.exec("UPDATE `user` SET password = ? WHERE id = ? ", [
|
await R.exec("UPDATE `user` SET password = ? WHERE id = ? ", [
|
||||||
passwordHash.generate(newPassword),
|
await passwordHash.generate(newPassword),
|
||||||
userID
|
userID
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@@ -25,7 +25,7 @@ class User extends BeanModel {
|
|||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
async resetPassword(newPassword) {
|
async resetPassword(newPassword) {
|
||||||
const hashedPassword = passwordHash.generate(newPassword);
|
const hashedPassword = await passwordHash.generate(newPassword);
|
||||||
|
|
||||||
await R.exec("UPDATE `user` SET password = ? WHERE id = ? ", [
|
await R.exec("UPDATE `user` SET password = ? WHERE id = ? ", [
|
||||||
hashedPassword,
|
hashedPassword,
|
||||||
|
@@ -5,10 +5,10 @@ const saltRounds = 10;
|
|||||||
/**
|
/**
|
||||||
* Hash a password
|
* Hash a password
|
||||||
* @param {string} password Password to hash
|
* @param {string} password Password to hash
|
||||||
* @returns {string} Hash
|
* @returns {Promise<string>} Hash
|
||||||
*/
|
*/
|
||||||
exports.generate = function (password) {
|
exports.generate = function (password) {
|
||||||
return bcrypt.hashSync(password, saltRounds);
|
return bcrypt.hash(password, saltRounds);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -674,7 +674,7 @@ let needSetup = false;
|
|||||||
|
|
||||||
let user = R.dispense("user");
|
let user = R.dispense("user");
|
||||||
user.username = username;
|
user.username = username;
|
||||||
user.password = passwordHash.generate(password);
|
user.password = await passwordHash.generate(password);
|
||||||
await R.store(user);
|
await R.store(user);
|
||||||
|
|
||||||
needSetup = false;
|
needSetup = false;
|
||||||
|
@@ -20,7 +20,7 @@ module.exports.apiKeySocketHandler = (socket) => {
|
|||||||
checkLogin(socket);
|
checkLogin(socket);
|
||||||
|
|
||||||
let clearKey = nanoid(40);
|
let clearKey = nanoid(40);
|
||||||
let hashedKey = passwordHash.generate(clearKey);
|
let hashedKey = await passwordHash.generate(clearKey);
|
||||||
key["key"] = hashedKey;
|
key["key"] = hashedKey;
|
||||||
let bean = await APIKey.save(key, socket.userID);
|
let bean = await APIKey.save(key, socket.userID);
|
||||||
|
|
||||||
|
@@ -14,7 +14,7 @@ module.exports.databaseSocketHandler = (socket) => {
|
|||||||
checkLogin(socket);
|
checkLogin(socket);
|
||||||
callback({
|
callback({
|
||||||
ok: true,
|
ok: true,
|
||||||
size: await Database.getSize(),
|
size: Database.getSize(),
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
callback({
|
callback({
|
||||||
|
@@ -51,7 +51,7 @@ exports.initJWTSecret = async () => {
|
|||||||
jwtSecretBean.key = "jwtSecret";
|
jwtSecretBean.key = "jwtSecret";
|
||||||
}
|
}
|
||||||
|
|
||||||
jwtSecretBean.value = passwordHash.generate(genSecret());
|
jwtSecretBean.value = await passwordHash.generate(genSecret());
|
||||||
await R.store(jwtSecretBean);
|
await R.store(jwtSecretBean);
|
||||||
return jwtSecretBean;
|
return jwtSecretBean;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user