From c511e497252986829c902c4f5dfb06959ad77f71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Wed, 19 Jul 2017 19:17:29 +0200 Subject: [PATCH] Server: update random password generation and add a "simple password" button --- server/index.php | 1 + server/resources/gpass.js | 42 ++++++++++++++++++++++++++------------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/server/index.php b/server/index.php index d8b0146..870af7a 100644 --- a/server/index.php +++ b/server/index.php @@ -163,6 +163,7 @@ if ($user != "") echo 'password '; echo 'master key '; echo ''; + echo ''; echo ""; echo "
"; echo '
Master key strength
0%
 
'; diff --git a/server/resources/gpass.js b/server/resources/gpass.js index ed00979..0ebac4c 100755 --- a/server/resources/gpass.js +++ b/server/resources/gpass.js @@ -50,27 +50,16 @@ Element.prototype.removeAllChilds = function() { this.removeChild(this.childNodes[0]); }; -function generate_random(size, only_ascii) +function _generate_random(size, symbols) { - // symbols 32 - 47 / 58 - 64 / 91 - 96 / 123 - 126 - // numbers 48 - 57 - // upper 65 - 90 - // lower 97 - 122 - // Give priority to letters (65 - 122 duplicated in front and end of array) - var symbols; - if (only_ascii) - symbols = new Array(65, 90, 97, 122, 40, 47, 48, 57, 65, 90, 97, 122, 123, 126, 65, 90, 97, 122); - else - symbols = new Array(1, 255); - forbidden = new Array('\\'); var res = ""; while (res.length < size) { - a = Math.round(Math.random() * (symbols.length/2) * 2); + a = Math.floor(Math.random() * (symbols.length/2)) * 2; diff = symbols[a+1] - symbols[a]; - r = Math.round(Math.random()*diff); + r = Math.floor(Math.random()*diff); if (isNaN(r+symbols[a])) continue; character = String.fromCharCode(r + symbols[a]); @@ -89,12 +78,37 @@ function generate_random(size, only_ascii) return res; } +function generate_random(size, only_ascii) +{ + // symbols 32 - 47 / 58 - 64 / 91 - 96 / 123 - 126 + // numbers 48 - 57 + // upper 65 - 90 + // lower 97 - 122 + // Give priority to letters (65 - 122 duplicated) + var symbols; + if (only_ascii) + symbols = new Array(32, 47, 48, 57, 58, 64, 91, 96, 123, 126, 65, 90, 97, 122, 65, 90, 97, 122, 48, 57); + else + symbols = new Array(1, 255); + + return _generate_random(size, symbols); +} function generate_password() { document.getElementById("new_password").value = generate_random(16, true); } +function generate_simple_password() +{ + // ! ( ) * + - . _ + // numbers 48 - 57 + // upper 65 - 90 + // lower 97 - 122 + symbols = new Array(33, 33, 40, 43, 45, 46, 95, 95, 48, 57, 65, 90, 97, 122, 48, 57, 65, 90, 97, 122, 48, 57, 48, 57, 65, 90, 97, 122); + document.getElementById("new_password").value = _generate_random(8, symbols); +} + function url_domain(data) { var uri = parseUri(data) return uri['host'];