1
0
mirror of https://github.com/hack-chat/main.git synced 2024-03-22 13:20:33 +08:00

Extended trip length to ten characters

This commit is contained in:
marzavec 2022-08-11 09:40:43 -05:00
parent b80b5ca9d1
commit 9982207983
3 changed files with 8 additions and 4 deletions

View File

@ -15,6 +15,8 @@ const {
createHash, createHash,
} = await import('crypto'); } = await import('crypto');
const TripLength = 10;
/** /**
* Object defining labels for default permission ranges * Object defining labels for default permission ranges
* @typedef {Object} levels * @typedef {Object} levels
@ -150,7 +152,7 @@ export function getUserPerms(pass, salt, config, channel) {
const sha = createHash('sha256'); const sha = createHash('sha256');
sha.update(pass + salt); 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 // check if user is global admin
if (trip === config.adminTrip) { if (trip === config.adminTrip) {

View File

@ -18,6 +18,8 @@ const SessionLocation = './session.key';
const SaltLocation = './salt.key'; const SaltLocation = './salt.key';
const AppConfigLocation = './config.json'; const AppConfigLocation = './config.json';
const TripLength = 10;
// default configuration options // default configuration options
const defaultConfig = { const defaultConfig = {
adminTrip: '', adminTrip: '',
@ -105,7 +107,7 @@ const checkPermissions = async () => {
const sha = crypto.createHash('sha256'); const sha = crypto.createHash('sha256');
sha.update(password + salt); 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(); await config.write();
} else { } else {

View File

@ -42,7 +42,7 @@ describe('Checking UAC module', () => {
it('should return admin level labels', async () => { it('should return admin level labels', async () => {
const newConfig = Object.assign({}, mocks.core.appConfig.data); const newConfig = Object.assign({}, mocks.core.appConfig.data);
newConfig.adminTrip = 'Tt8H7c'; newConfig.adminTrip = 'Tt8H7clbL9';
const resp = importedModule.getUserPerms('test', 'salt', newConfig, 'cake'); const resp = importedModule.getUserPerms('test', 'salt', newConfig, 'cake');
expect(resp).to.be.an('object'); expect(resp).to.be.an('object');
}); });
@ -50,7 +50,7 @@ describe('Checking UAC module', () => {
it('should return mod level labels', async () => { it('should return mod level labels', async () => {
const newConfig = Object.assign({}, mocks.core.appConfig.data); const newConfig = Object.assign({}, mocks.core.appConfig.data);
newConfig.globalMods = [{ newConfig.globalMods = [{
trip: 'Tt8H7c', trip: 'Tt8H7clbL9',
}]; }];
const resp = importedModule.getUserPerms('test', 'salt', newConfig, 'cake'); const resp = importedModule.getUserPerms('test', 'salt', newConfig, 'cake');
expect(resp).to.be.an('object'); expect(resp).to.be.an('object');