Modify GeneratorPresets and PasswordGenerator directly

By modifying these objects, both the generator view and the generator presets view are affected.
This commit is contained in:
Grant Moyer 2022-03-28 23:22:33 -04:00
parent d78e242b82
commit 0003a45efc
2 changed files with 37 additions and 27 deletions

View File

@ -9,9 +9,9 @@
"url": "https://github.com/GrantMoyer/" "url": "https://github.com/GrantMoyer/"
}, },
"resources": { "resources": {
"js": "xI48tPthMnRvBDqUtz0/eX1fNYCdpAFfNd8vswWsuGPucj4BYei2fntsqBBW3R8yaFsiuh5UV8Zz+7kb5AgP4UVOU0Rip9kFmrgCHGo8cvvEWQa9KDFBvv+OvotCSllxT9ise4LNtfXQtoRXXZdWAqPsjZ3nfKhI/Al3n8QghXteNWiuvwX4D85S0VPJpL/sY4dUblFRz+GLj0E2QRbWhBsU5ccvdP50GNo0QJvSuiD59VUd+bRnjpaB4YofuR59D6Y4qAFjZqGlMIlRM5h2tmD11GLDXa7ZTVbWy1zKwz/Cn6TjwMQXFqAhh4xshkPF/KeNfYW1csZ0lYTbgHUPRQ==" "js": "awImbm3h4cVUvt9b7hHs0PyzkGMVHp4zvk+/J8bXvePYok6KjRF7jPrmUxMHYhVX7n+F0TUQOl3S9UHIWPjBy1bYU5mwZD1ZS+/Gz5dBsrXK7Q0Jk/Cb8t9jtTcC5opKtZW3fGvvNCSzN+iKySJn14Q0gpmVlScMtw7S5P6RRz9z+QDP7vzo3UN9mhIi0E9b8S/wmoynGDTHivtuPoKbLdM1Sp/Qsuz3Rirkv8N+UTDbB3xYuCG9b3TvKDjXIHAcpMkKW4tOy9ALYBVWv3qgSy40JU0as/SGee24B1Q7bklVzbuM7b5TV2HYOLP6ZV5xw8I8fzcMdnXymPqwGbdm2A=="
}, },
"licence": "MIT", "licence": "MIT",
"url": "https://github.com/GrantMoyer/keeweb-plugin-passphrase-generator", "url": "https://github.com/GrantMoyer/keeweb-plugin-passphrase-generator",
"publicKey": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzOR25PG6eC40WZQvhia4tln4VEfafbuu+w1PQ88E4cJM6NZqZBxtJjA+0wMPHU+y2WlWMBgiEKanQYjy8JgNJSzUX3LvwzabnSb5EhJwyELvkqTlHupNhZXcQfCNc9awQSJT1wBnookq7r/CAHCPDaAS6EzdDKDOxTNiKYSp+hubln7bJwxgNfkL4WbapV1ZyJqU0Vcjl8btOoZpAWc0KtWqt893sBkuy8orcf8taChvtVWecW4zsBGRLKUG0WRN0t8zDpe+NHzL2JXyA/e44gahqbLuwXucg6zYGzFGxvKQAdNlQ/+tcBQ7nNUo13RahKpGGJVrzzDwVDcdJL0H8wIDAQAB" "publicKey": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzOR25PG6eC40WZQvhia4tln4VEfafbuu+w1PQ88E4cJM6NZqZBxtJjA+0wMPHU+y2WlWMBgiEKanQYjy8JgNJSzUX3LvwzabnSb5EhJwyELvkqTlHupNhZXcQfCNc9awQSJT1wBnookq7r/CAHCPDaAS6EzdDKDOxTNiKYSp+hubln7bJwxgNfkL4WbapV1ZyJqU0Vcjl8btOoZpAWc0KtWqt893sBkuy8orcf8taChvtVWecW4zsBGRLKUG0WRN0t8zDpe+NHzL2JXyA/e44gahqbLuwXucg6zYGzFGxvKQAdNlQ/+tcBQ7nNUo13RahKpGGJVrzzDwVDcdJL0H8wIDAQAB"
} }

View File

@ -4,39 +4,49 @@
* @license MIT * @license MIT
*/ */
const { GeneratorView } = require('views/generator-view'); const { GeneratorPresets } = require('comp/app/generator-presets')
const Kdbxweb = require('kdbxweb'); const Kdbxweb = require('kdbxweb');
const { PasswordGenerator } = require('util/generators/password-generator'); const { PasswordGenerator } = require('util/generators/password-generator');
let generatorViewGenerate = GeneratorView.prototype.generate; let generatorPresetsBuiltIn = Object.getOwnPropertyDescriptor(GeneratorPresets, 'builtIn');
GeneratorView.prototype.generate = function() { Object.defineProperty(GeneratorPresets, 'builtInOriginal', generatorPresetsBuiltIn);
if (!this.gen || this.gen.title !== 'passphrase') return generatorViewGenerate.apply(this); Object.defineProperty(GeneratorPresets, 'builtIn', {
if (typeof this.gen.length !== 'number' || this.gen.length < 0) { get: function() {
const presets = this.builtInOriginal;
presets.push({
name: 'passphrase',
title: 'passphrase',
type: 'passphrase',
builtIn: true,
options: [{
name: 'dash',
title: 'Use dash as word seperator',
label: '-',
type: 'checkbox'
}],
dash: true,
length: 6
})
return presets;
}
})
let passwordGeneratorGenerate = PasswordGenerator.generate;
PasswordGenerator.generate = function(preset) {
if (preset.type !== 'passphrase') return passwordGeneratorGenerate(preset);
if (typeof preset.length !== 'number' || preset.length < 0) {
return ''; return '';
} }
this.password = Array const password = Array
.from({length: this.gen.length}, _ => eff_large_wordlist()[get_random_index()]) .from({length: preset.length}, _ => eff_large_wordlist()[get_random_index()])
.join(' '); .join(preset.dash ? '-' : ' ');
this.showPassword(); return password;
const isLong = this.password.length > 32;
this.resultEl.toggleClass('gen__result--long-pass', isLong);
}
let generatorViewCreatePresets = GeneratorView.prototype.createPresets;
GeneratorView.prototype.createPresets = function() {
generatorViewCreatePresets.apply(this);
this.presets.unshift({
name: 'passphrase',
title: 'passphrase',
builtIn: true,
length: 6
});
this.lengthToPseudoValue(this.presets[0]);
} }
module.exports.uninstall = function() { module.exports.uninstall = function() {
GeneratorView.prototype.generate = generatorViewGenerate; Object.defineProperty(GeneratorPresets, 'builtIn', generatorPresetsBuiltIn);
GeneratorView.prototype.createPresets = generatorViewCreatePresets; Object.defineProperty(GeneratorPresets, 'builtInOriginal', {});
PasswordGenerator.generate = passwordGeneratorGenerate;
}; };
function get_random_index() { function get_random_index() {