2013-10-09 20:47:43 +02:00
|
|
|
// parseUri 1.2.2
|
|
|
|
// (c) Steven Levithan <stevenlevithan.com>
|
|
|
|
// MIT License
|
|
|
|
// http://blog.stevenlevithan.com/archives/parseuri
|
|
|
|
function parseUri (str) {
|
|
|
|
var o = parseUri.options,
|
|
|
|
m = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
|
|
|
|
uri = {},
|
|
|
|
i = 14;
|
|
|
|
|
|
|
|
while (i--) uri[o.key[i]] = m[i] || "";
|
|
|
|
|
|
|
|
uri[o.q.name] = {};
|
|
|
|
uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
|
|
|
|
if ($1) uri[o.q.name][$1] = $2;
|
|
|
|
});
|
|
|
|
|
|
|
|
return uri;
|
|
|
|
};
|
|
|
|
|
|
|
|
parseUri.options = {
|
|
|
|
strictMode: false,
|
|
|
|
key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
|
|
|
|
q: {
|
|
|
|
name: "queryKey",
|
|
|
|
parser: /(?:^|&)([^&=]*)=?([^&]*)/g
|
|
|
|
},
|
|
|
|
parser: {
|
|
|
|
strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
|
|
|
|
loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function generate_password()
|
|
|
|
{
|
|
|
|
// symbols 32 - 47 / 58 - 64 / 91 - 96 / 123 - 126
|
|
|
|
// numbers 48 - 57
|
|
|
|
// upper 65 - 90
|
|
|
|
// lower 97 - 122
|
2013-10-16 18:40:06 +02:00
|
|
|
// Give priority to letters (65 - 122 duplicated in front and end of array)
|
|
|
|
var symbols = new Array(65, 90, 97, 122, 40, 47, 48, 57, 65, 90, 97, 122, 123, 126, 65, 90, 97, 122);
|
2013-10-09 20:47:43 +02:00
|
|
|
|
|
|
|
field = document.getElementById("new_password");
|
|
|
|
|
|
|
|
var res = "";
|
|
|
|
while (res.length < 16)
|
|
|
|
{
|
|
|
|
a = Math.round(Math.random() * (symbols.length/2) * 2);
|
|
|
|
diff = symbols[a+1] - symbols[a];
|
|
|
|
r = Math.round(Math.random()*diff);
|
|
|
|
if (isNaN(r+symbols[a]))
|
|
|
|
continue;
|
|
|
|
res += String.fromCharCode(r + symbols[a]);
|
|
|
|
}
|
|
|
|
|
|
|
|
field.value = res;
|
|
|
|
}
|
|
|
|
|
|
|
|
function url_domain(data) {
|
|
|
|
var uri = parseUri(data)
|
|
|
|
return uri['host'];
|
2013-10-15 21:02:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function a2hex(str) {
|
|
|
|
var hex = '';
|
|
|
|
for (var i = 0; i < str.length; i++)
|
|
|
|
{
|
|
|
|
c = str.charCodeAt(i).toString(16);
|
|
|
|
if (c.length == 1) c = "0" + c;
|
|
|
|
hex += c;
|
|
|
|
}
|
|
|
|
return hex;
|
|
|
|
}
|
|
|
|
|
|
|
|
function derive_mkey(user, mkey_target)
|
|
|
|
{
|
|
|
|
mkey_target = document.getElementById(mkey_target) ;
|
|
|
|
mkey = mkey_target.value;
|
|
|
|
|
|
|
|
if (mkey.length == 0)
|
|
|
|
{
|
|
|
|
alert('Empty master key');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
url = url_domain(document.URL) + "/" + user;
|
2013-10-16 07:55:13 +02:00
|
|
|
mkey = a2hex(pkdbf2(mkey, url, 1000, 256/8));
|
2013-10-15 21:02:14 +02:00
|
|
|
mkey_target.value = mkey;
|
|
|
|
|
|
|
|
return true;
|
2013-10-09 20:47:43 +02:00
|
|
|
}
|