From 99822079833cc14d83715d1c8f3982a9cf2c7a7b Mon Sep 17 00:00:00 2001 From: marzavec Date: Thu, 11 Aug 2022 09:40:43 -0500 Subject: [PATCH] Extended trip length to ten characters --- commands/utility/_UAC.js | 4 +++- scripts/config.js | 4 +++- test/uac.test.js | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/commands/utility/_UAC.js b/commands/utility/_UAC.js index f003288..96a9332 100644 --- a/commands/utility/_UAC.js +++ b/commands/utility/_UAC.js @@ -15,6 +15,8 @@ const { createHash, } = await import('crypto'); +const TripLength = 10; + /** * Object defining labels for default permission ranges * @typedef {Object} levels @@ -150,7 +152,7 @@ export function getUserPerms(pass, salt, config, channel) { const sha = createHash('sha256'); sha.update(pass + salt); - const trip = sha.digest('base64').substr(0, 6); + const trip = sha.digest('base64').substr(0, TripLength); // check if user is global admin if (trip === config.adminTrip) { diff --git a/scripts/config.js b/scripts/config.js index 89d3d80..eb8e875 100644 --- a/scripts/config.js +++ b/scripts/config.js @@ -18,6 +18,8 @@ const SessionLocation = './session.key'; const SaltLocation = './salt.key'; const AppConfigLocation = './config.json'; +const TripLength = 10; + // default configuration options const defaultConfig = { adminTrip: '', @@ -105,7 +107,7 @@ const checkPermissions = async () => { const sha = crypto.createHash('sha256'); sha.update(password + salt); - config.data.adminTrip = sha.digest('base64').substr(0, 6); + config.data.adminTrip = sha.digest('base64').substr(0, TripLength); await config.write(); } else { diff --git a/test/uac.test.js b/test/uac.test.js index be017e1..f64bada 100644 --- a/test/uac.test.js +++ b/test/uac.test.js @@ -42,7 +42,7 @@ describe('Checking UAC module', () => { it('should return admin level labels', async () => { const newConfig = Object.assign({}, mocks.core.appConfig.data); - newConfig.adminTrip = 'Tt8H7c'; + newConfig.adminTrip = 'Tt8H7clbL9'; const resp = importedModule.getUserPerms('test', 'salt', newConfig, 'cake'); expect(resp).to.be.an('object'); }); @@ -50,7 +50,7 @@ describe('Checking UAC module', () => { it('should return mod level labels', async () => { const newConfig = Object.assign({}, mocks.core.appConfig.data); newConfig.globalMods = [{ - trip: 'Tt8H7c', + trip: 'Tt8H7clbL9', }]; const resp = importedModule.getUserPerms('test', 'salt', newConfig, 'cake'); expect(resp).to.be.an('object');