Server: update random password generation and add a "simple password" button
This commit is contained in:
parent
8469c01b13
commit
c511e49725
|
@ -163,6 +163,7 @@ if ($user != "")
|
|||
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 '<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 "<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"> </div></div></div>';
|
||||
|
|
|
@ -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'];
|
||||
|
|
Loading…
Reference in New Issue
Block a user