Server: update random password generation and add a "simple password" button

This commit is contained in:
Grégory Soutadé 2017-07-19 19:17:29 +02:00
parent 8469c01b13
commit c511e49725
2 changed files with 29 additions and 14 deletions

View File

@ -163,6 +163,7 @@ if ($user != "")
echo 'password <input id="new_password" type="text" name="password"/>'; echo 'password <input id="new_password" type="text" name="password"/>';
echo 'master key <input type="text" name="mkey" onkeypress="if (event.keyCode == 13) add_password();" onkeyup="chkPass(this.value);"/>'; echo 'master key <input type="text" name="mkey" onkeypress="if (event.keyCode == 13) add_password();" onkeyup="chkPass(this.value);"/>';
echo '<input type="button" value="Generate password" onClick="generate_password();"/>'; echo '<input type="button" value="Generate password" onClick="generate_password();"/>';
echo '<input type="button" value="Generate simple password" onClick="generate_simple_password();"/>';
echo "<input type=\"button\" name=\"add\" value=\"Add\" onclick=\"add_password();\"/>"; echo "<input type=\"button\" name=\"add\" value=\"Add\" onclick=\"add_password();\"/>";
echo "<br />"; echo "<br />";
echo '<div><a href="http://en.wikipedia.org/wiki/Password_strength">Master key strength</a><div id="scorebarBorder"><div id="score">0%</div><div id="scorebar">&nbsp;</div></div></div>'; echo '<div><a href="http://en.wikipedia.org/wiki/Password_strength">Master key strength</a><div id="scorebarBorder"><div id="score">0%</div><div id="scorebar">&nbsp;</div></div></div>';

View File

@ -50,27 +50,16 @@ Element.prototype.removeAllChilds = function() {
this.removeChild(this.childNodes[0]); 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('\\'); forbidden = new Array('\\');
var res = ""; var res = "";
while (res.length < size) 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]; diff = symbols[a+1] - symbols[a];
r = Math.round(Math.random()*diff); r = Math.floor(Math.random()*diff);
if (isNaN(r+symbols[a])) if (isNaN(r+symbols[a]))
continue; continue;
character = String.fromCharCode(r + symbols[a]); character = String.fromCharCode(r + symbols[a]);
@ -89,12 +78,37 @@ function generate_random(size, only_ascii)
return res; 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() function generate_password()
{ {
document.getElementById("new_password").value = generate_random(16, true); 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) { function url_domain(data) {
var uri = parseUri(data) var uri = parseUri(data)
return uri['host']; return uri['host'];