From c66fa828753f3c6a5871ead3c28ce27c74ada520 Mon Sep 17 00:00:00 2001 From: s2 Date: Tue, 28 Nov 2017 22:00:00 +0100 Subject: [PATCH] exclude characters option --- src/popup/pwgen.css | 4 ++++ src/popup/pwgen.html | 5 +++++ src/popup/pwgen.js | 15 ++++++++++++--- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/popup/pwgen.css b/src/popup/pwgen.css index b6ce06e..333d61b 100644 --- a/src/popup/pwgen.css +++ b/src/popup/pwgen.css @@ -41,6 +41,10 @@ input[type="checkbox"] { margin-left: 0px; } +#exclude { + width: 183px; +} + .copied { pointer-events: none; height: 26px; diff --git a/src/popup/pwgen.html b/src/popup/pwgen.html index 4b50758..6dd52c2 100644 --- a/src/popup/pwgen.html +++ b/src/popup/pwgen.html @@ -28,6 +28,11 @@ +
+ + +
+
diff --git a/src/popup/pwgen.js b/src/popup/pwgen.js index 1ff6a8b..281b8e0 100644 --- a/src/popup/pwgen.js +++ b/src/popup/pwgen.js @@ -1,9 +1,15 @@ -function randPassword(length, includeSpecial) { +function randPassword(length, includeSpecial, exclude) { let pwdChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; if (includeSpecial) { pwdChars += '°^!"§$%&/()=?`´\\}][{²³€|<>-.,;:*+_µ@~'; } + if (exclude) { + exclude.split('').forEach(c => { + pwdChars = pwdChars.split(c).join(''); + }); + } + let randValues = new Uint32Array(length); let randPwd = ''; window.crypto.getRandomValues(randValues); @@ -23,6 +29,7 @@ function getParams() { lengthMin: parseInt(document.getElementById('length-min').value), lengthMax: parseInt(document.getElementById('length-max').value), special: document.getElementById('special').checked, + exclude: document.getElementById('exclude').value, directcopy: document.getElementById('directcopy').checked } } @@ -32,6 +39,7 @@ function loadOptions() { lengthMin: 14, lengthMax: 17, special: true, + exclude: 'iIl|10o8B3Evu![]{}', directcopy: false }); } @@ -71,7 +79,7 @@ document.addEventListener('DOMContentLoaded', function() { document.getElementById('new').addEventListener('click', (ev) => { ev.preventDefault(); var params = getParams(); - document.getElementById('pw').value = randPassword(generateLength(), params.special); + document.getElementById('pw').value = randPassword(generateLength(), params.special, params.exclude); }); document.getElementById('copy').addEventListener('click', (ev) => { @@ -90,8 +98,9 @@ document.addEventListener('DOMContentLoaded', function() { document.getElementById('length-min').value = options.lengthMin; document.getElementById('length-max').value = options.lengthMax; document.getElementById('special').checked = options.special; + document.getElementById('exclude').value = options.exclude; document.getElementById('directcopy').checked = options.directcopy; - document.getElementById('pw').value = randPassword(generateLength(), getParams().special); + document.getElementById('pw').value = randPassword(generateLength(), getParams().special, getParams().exclude); if (options.directcopy) { copypasstoclippboard();