mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-01 03:53:57 +00:00
SYNC: encrypt superadmin password
This commit is contained in:
committed by
Diflow
parent
7c7d6ad548
commit
dd210be037
@@ -12,6 +12,7 @@ const {
|
|||||||
getAuthProviderById,
|
getAuthProviderById,
|
||||||
} = require('../auth/authProvider');
|
} = require('../auth/authProvider');
|
||||||
const storage = require('./storage');
|
const storage = require('./storage');
|
||||||
|
const { decryptPasswordString } = require('../utility/crypting');
|
||||||
|
|
||||||
const logger = getLogger('auth');
|
const logger = getLogger('auth');
|
||||||
|
|
||||||
@@ -95,7 +96,7 @@ module.exports = {
|
|||||||
let adminPassword = process.env.ADMIN_PASSWORD;
|
let adminPassword = process.env.ADMIN_PASSWORD;
|
||||||
if (!adminPassword) {
|
if (!adminPassword) {
|
||||||
const adminConfig = await storage.readConfig({ group: 'admin' });
|
const adminConfig = await storage.readConfig({ group: 'admin' });
|
||||||
adminPassword = adminConfig?.adminPassword;
|
adminPassword = decryptPasswordString(adminConfig?.adminPassword);
|
||||||
}
|
}
|
||||||
if (adminPassword && adminPassword == password) {
|
if (adminPassword && adminPassword == password) {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -67,6 +67,20 @@ function getEncryptor() {
|
|||||||
return _encryptor;
|
return _encryptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function encryptPasswordString(password) {
|
||||||
|
if (password && !password.startsWith('crypt:')) {
|
||||||
|
return 'crypt:' + getEncryptor().encrypt(password);
|
||||||
|
}
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
function decryptPasswordString(password) {
|
||||||
|
if (password && password.startsWith('crypt:')) {
|
||||||
|
return getEncryptor().decrypt(password.substring('crypt:'.length));
|
||||||
|
}
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
function encryptObjectPasswordField(obj, field) {
|
function encryptObjectPasswordField(obj, field) {
|
||||||
if (obj && obj[field] && !obj[field].startsWith('crypt:')) {
|
if (obj && obj[field] && !obj[field].startsWith('crypt:')) {
|
||||||
return {
|
return {
|
||||||
@@ -153,4 +167,6 @@ module.exports = {
|
|||||||
loadEncryptionKeyFromExternal,
|
loadEncryptionKeyFromExternal,
|
||||||
getEncryptionKey,
|
getEncryptionKey,
|
||||||
setEncryptionKey,
|
setEncryptionKey,
|
||||||
|
encryptPasswordString,
|
||||||
|
decryptPasswordString,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user