Rename resSources directories into resources
This commit is contained in:
BIN
server/resources/bg_strength_gradient.jpg
Normal file
BIN
server/resources/bg_strength_gradient.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 676 B |
BIN
server/resources/favicon.png
Executable file
BIN
server/resources/favicon.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
108
server/resources/gpass.css
Executable file
108
server/resources/gpass.css
Executable file
@@ -0,0 +1,108 @@
|
||||
|
||||
body {
|
||||
background-image:linear-gradient(#0096ff 30%, white);
|
||||
height:100%; width:100%;
|
||||
}
|
||||
|
||||
#logo {
|
||||
display:block;
|
||||
margin-left:auto;
|
||||
margin-right:auto;
|
||||
margin-top:30px;
|
||||
margin-bottom:40px;
|
||||
text-align:center;
|
||||
}
|
||||
|
||||
#admin {
|
||||
border-style:solid;
|
||||
border-width:5px;
|
||||
border-color:red;
|
||||
padding : 15px;
|
||||
margin : 15px;
|
||||
}
|
||||
|
||||
#admin form {
|
||||
text-align : center;
|
||||
}
|
||||
|
||||
#user {
|
||||
border-style:solid;
|
||||
border-width:5px;
|
||||
border-color:green;
|
||||
padding : 15px;
|
||||
margin : 15px;
|
||||
text-align:center;
|
||||
}
|
||||
|
||||
#user input {
|
||||
margin-left : 15px;
|
||||
margin-right : 30px;
|
||||
margin-top : 10px;
|
||||
margin-bottom : 10px;
|
||||
}
|
||||
|
||||
#select_user {
|
||||
text-align : center;
|
||||
}
|
||||
|
||||
#passwords {
|
||||
border-style:solid;
|
||||
border-width:5px;
|
||||
border-color:grey;
|
||||
padding : 15px;
|
||||
margin : 15px;
|
||||
}
|
||||
|
||||
#addon_address {
|
||||
padding:10px;
|
||||
text-align:center;
|
||||
font-size:xx-large;
|
||||
}
|
||||
|
||||
.hash {
|
||||
width : 700px;
|
||||
}
|
||||
|
||||
#add_new_password {
|
||||
border-style:solid;
|
||||
border-width:5px;
|
||||
border-color:blue;
|
||||
padding : 15px;
|
||||
margin : 15px;
|
||||
}
|
||||
|
||||
.error {
|
||||
text-align:center;
|
||||
color:red;
|
||||
font-weight:bold;
|
||||
font-size:xx-large;
|
||||
}
|
||||
|
||||
#scorebarBorder {
|
||||
background: #333;
|
||||
border: 1px #000 solid;
|
||||
height: 16px;
|
||||
margin-bottom: 2px;
|
||||
margin-left:auto;
|
||||
margin-right:auto;
|
||||
width: 100px;
|
||||
}
|
||||
|
||||
#score {
|
||||
color: rgb(0, 0, 0);
|
||||
font-size: 85%;
|
||||
position: absolute;
|
||||
text-align: center;
|
||||
width: 100px;
|
||||
z-index: 10;
|
||||
font-weight:bold;
|
||||
}
|
||||
|
||||
#scorebar {
|
||||
background-image: url(/ressources/bg_strength_gradient.jpg);
|
||||
background-repeat: no-repeat;
|
||||
background-position: 0 0;
|
||||
position:absolute;
|
||||
width: 100px;
|
||||
z-index: 0;
|
||||
}
|
657
server/resources/gpass.js
Executable file
657
server/resources/gpass.js
Executable file
@@ -0,0 +1,657 @@
|
||||
// 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*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
|
||||
}
|
||||
};
|
||||
|
||||
if (!String.prototype.trim) {
|
||||
String.prototype.trim = function() {
|
||||
return this.replace(/^\s+|\s+$/g, "");
|
||||
};
|
||||
}
|
||||
|
||||
// Array Remove - By John Resig (MIT Licensed)
|
||||
// http://stackoverflow.com/questions/500606/javascript-array-delete-elements
|
||||
Array.prototype.remove = function(from, to) {
|
||||
var rest = this.slice((to || from) + 1 || this.length);
|
||||
this.length = from < 0 ? this.length + from : from;
|
||||
return this.push.apply(this, rest);
|
||||
};
|
||||
|
||||
Element.prototype.removeAllChilds = function() {
|
||||
while (this.hasChildNodes())
|
||||
this.removeChild(this.childNodes[0]);
|
||||
};
|
||||
|
||||
|
||||
function generate_password()
|
||||
{
|
||||
// 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 = new Array(65, 90, 97, 122, 40, 47, 48, 57, 65, 90, 97, 122, 123, 126, 65, 90, 97, 122);
|
||||
|
||||
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'];
|
||||
}
|
||||
|
||||
// http://stackoverflow.com/questions/3745666/how-to-convert-from-hex-to-ascii-in-javascript
|
||||
function hex2a(hex) {
|
||||
var str = '';
|
||||
for (var i = 0; i < hex.length; i += 2)
|
||||
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
|
||||
return str;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
url = url_domain(document.URL) + "/" + user;
|
||||
mkey = a2hex(pkdbf2(mkey, url, pkdbf2_level, 256/8));
|
||||
return mkey;
|
||||
}
|
||||
|
||||
var passwords;
|
||||
var current_user = "";
|
||||
var current_mkey = "";
|
||||
|
||||
function PasswordEntry (ciphered_login, ciphered_password) {
|
||||
this.ciphered_login = ciphered_login;
|
||||
this.ciphered_password = ciphered_password;
|
||||
this.unciphered = false;
|
||||
this.clear_url = "";
|
||||
this.clear_login = "";
|
||||
this.clear_password = "";
|
||||
this.masterkey = "";
|
||||
|
||||
this.decrypt = function(masterkey)
|
||||
{
|
||||
if (masterkey == this.masterkey && this.unciphered == true)
|
||||
return true;
|
||||
|
||||
if (masterkey == "" || this.unciphered == true)
|
||||
return false;
|
||||
|
||||
aes = new AES();
|
||||
a_masterkey = aes.init(hex2a(masterkey));
|
||||
login = aes.decryptLongString(hex2a(this.ciphered_login), a_masterkey);
|
||||
login = login.replace(/\0*$/, "");
|
||||
if (login.indexOf("@@") != 0)
|
||||
{
|
||||
aes.finish();
|
||||
return false;
|
||||
}
|
||||
// Remove @@
|
||||
login = login.substring(2);
|
||||
infos = login.split(";");
|
||||
this.clear_url = infos[0];
|
||||
this.clear_login = infos[1];
|
||||
this.clear_password = aes.decryptLongString(hex2a(this.ciphered_password), a_masterkey);
|
||||
this.unciphered = true;
|
||||
this.masterkey = masterkey;
|
||||
aes.finish();
|
||||
|
||||
// Remove salt
|
||||
this.clear_password = this.clear_password.replace(/\0*$/, "");
|
||||
this.clear_password = this.clear_password.substr(0, this.clear_password.length-3);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
this.isUnciphered = function(masterkey)
|
||||
{
|
||||
return (this.unciphered == true && masterkey == this.masterkey && masterkey != "")
|
||||
}
|
||||
|
||||
this.isCiphered = function(masterkey)
|
||||
{
|
||||
return !(this.isUnciphered(masterkey));
|
||||
}
|
||||
}
|
||||
|
||||
function list_all_entries(user)
|
||||
{
|
||||
passwords = new Array();
|
||||
|
||||
req = new XMLHttpRequest();
|
||||
req.addEventListener("load", function(evt) {
|
||||
entries = this.responseText.split("\n");
|
||||
if (entries[0] == "entries")
|
||||
{
|
||||
for(i=1; i<entries.length; i++)
|
||||
{
|
||||
if (entries[i] == "") continue;
|
||||
entry = entries[i].split(";");
|
||||
passwords.push(new PasswordEntry(entry[0], entry[1]));
|
||||
}
|
||||
}
|
||||
}, false);
|
||||
req.open("POST", document.documentURI, false);
|
||||
req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
|
||||
req.send("get_passwords=1&user=" + user);
|
||||
}
|
||||
|
||||
function update_stats()
|
||||
{
|
||||
nb_ciphered_passwords = 0;
|
||||
nb_unciphered_passwords = 0;
|
||||
|
||||
for(i=0; i<passwords.length; i++)
|
||||
{
|
||||
if (passwords[i].isUnciphered(current_mkey))
|
||||
nb_unciphered_passwords++;
|
||||
else
|
||||
nb_ciphered_passwords++;
|
||||
}
|
||||
|
||||
div = document.getElementById("nb_unciphered_passwords");
|
||||
div.removeAllChilds();
|
||||
|
||||
text = document.createElement("b");
|
||||
text.appendChild(document.createTextNode(nb_unciphered_passwords + " unciphered password(s)"));
|
||||
div.appendChild(text);
|
||||
div.appendChild(document.createElement("br"));
|
||||
div.appendChild(document.createElement("br"));
|
||||
|
||||
div = document.getElementById("nb_ciphered_passwords");
|
||||
div.removeAllChilds();
|
||||
|
||||
text = document.createElement("b");
|
||||
text.appendChild(document.createTextNode(nb_ciphered_passwords + " ciphered password(s)"));
|
||||
div.appendChild(text);
|
||||
div.appendChild(document.createElement("br"));
|
||||
div.appendChild(document.createElement("br"));
|
||||
}
|
||||
|
||||
function change_master_key(warning_unciphered)
|
||||
{
|
||||
var nb_unciphered = 0;
|
||||
for(i=0; i<passwords.length; i++)
|
||||
{
|
||||
if (passwords[i].decrypt(current_mkey))
|
||||
nb_unciphered++;
|
||||
}
|
||||
|
||||
|
||||
if (!nb_unciphered && warning_unciphered)
|
||||
alert("No password unciphered with this master key !");
|
||||
|
||||
password_div = document.getElementById("passwords");
|
||||
password_div.removeAllChilds();
|
||||
|
||||
div = document.createElement("div");
|
||||
div.setAttribute("id", "nb_unciphered_passwords");
|
||||
password_div.appendChild(div);
|
||||
|
||||
for(i=0; i<passwords.length; i++)
|
||||
{
|
||||
if (passwords[i].isUnciphered(current_mkey))
|
||||
{
|
||||
div = document.createElement("div");
|
||||
div.setAttribute("id", "unciph_entry_" + i);
|
||||
div.setAttribute("class", "password");
|
||||
|
||||
ciph_login = document.createElement("input");
|
||||
ciph_login.setAttribute("name", "ciphered_login");
|
||||
ciph_login.setAttribute("type", "hidden");
|
||||
ciph_login.setAttribute("login", passwords[i].ciphered_login);
|
||||
div.appendChild(ciph_login);
|
||||
|
||||
div.appendChild(document.createTextNode("URL"));
|
||||
url = document.createElement("input");
|
||||
url.setAttribute("type", "text");
|
||||
url.setAttribute("name", "url");
|
||||
url.setAttribute("value", passwords[i].clear_url);
|
||||
div.appendChild(url);
|
||||
|
||||
div.appendChild(document.createTextNode("login"));
|
||||
login = document.createElement("input");
|
||||
login.setAttribute("type", "text");
|
||||
login.setAttribute("name", "login");
|
||||
login.setAttribute("value", passwords[i].clear_login);
|
||||
div.appendChild(login);
|
||||
|
||||
div.appendChild(document.createTextNode("password"));
|
||||
password = document.createElement("input");
|
||||
password.setAttribute("type", "text");
|
||||
password.setAttribute("name", "password");
|
||||
password.setAttribute("value", passwords[i].clear_password);
|
||||
div.appendChild(password);
|
||||
|
||||
delete_button = document.createElement("input");
|
||||
delete_button.setAttribute("type", "button");
|
||||
delete_button.setAttribute("value", "Delete");
|
||||
delete_button.setAttribute("onclick", "delete_entry(\"unciph_entry_" + i + "\");");
|
||||
div.appendChild(delete_button);
|
||||
|
||||
update_button = document.createElement("input");
|
||||
update_button.setAttribute("type", "button");
|
||||
update_button.setAttribute("value", "Update");
|
||||
update_button.setAttribute("onclick", "update_entry(\"unciph_entry_" + i + "\");");
|
||||
div.appendChild(update_button);
|
||||
|
||||
password_div.appendChild(div);
|
||||
}
|
||||
}
|
||||
|
||||
div = document.createElement("div");
|
||||
div.setAttribute("id", "nb_ciphered_passwords");
|
||||
password_div.appendChild(div);
|
||||
|
||||
for(i=0; i<passwords.length; i++)
|
||||
{
|
||||
if (passwords[i].isCiphered(current_mkey))
|
||||
{
|
||||
div = document.createElement("div");
|
||||
div.setAttribute("id", "ciph_entry_" + i);
|
||||
div.setAttribute("class", "password");
|
||||
|
||||
ciph_login = document.createElement("input");
|
||||
ciph_login.setAttribute("name", "ciphered_login");
|
||||
ciph_login.setAttribute("type", "hidden");
|
||||
ciph_login.setAttribute("login", passwords[i].ciphered_login);
|
||||
div.appendChild(ciph_login);
|
||||
|
||||
div.appendChild(document.createTextNode("URL"));
|
||||
url = document.createElement("input");
|
||||
url.setAttribute("class", "hash");
|
||||
url.setAttribute("type", "text");
|
||||
url.setAttribute("name", "URL");
|
||||
url.setAttribute("value", passwords[i].ciphered_login);
|
||||
div.appendChild(url);
|
||||
|
||||
div.appendChild(document.createTextNode("password"));
|
||||
password = document.createElement("input");
|
||||
password.setAttribute("class", "hash");
|
||||
password.setAttribute("type", "text");
|
||||
password.setAttribute("name", "password");
|
||||
password.setAttribute("value", passwords[i].ciphered_password);
|
||||
div.appendChild(password);
|
||||
|
||||
delete_button = document.createElement("input");
|
||||
delete_button.setAttribute("type", "button");
|
||||
delete_button.setAttribute("value", "Delete");
|
||||
delete_button.setAttribute("onclick", "delete_entry(\"ciph_entry_" + i + "\");");
|
||||
div.appendChild(delete_button);
|
||||
|
||||
password_div.appendChild(div);
|
||||
}
|
||||
}
|
||||
|
||||
input = document.getElementById("master_key");
|
||||
input.value = "";
|
||||
|
||||
update_stats();
|
||||
}
|
||||
|
||||
function update_master_key(warning_unciphered)
|
||||
{
|
||||
user = select_widget.options[select_widget.selectedIndex].value;
|
||||
|
||||
if (user != current_user)
|
||||
{
|
||||
current_user = user;
|
||||
|
||||
document.title = "gPass - " + current_user;
|
||||
|
||||
list_all_entries(current_user);
|
||||
|
||||
addon_address = document.getElementById("addon_address");
|
||||
addon_address.removeAllChilds();
|
||||
|
||||
addon_address.appendChild(document.createTextNode("Current addon address is : " + document.documentURI + current_user));
|
||||
|
||||
warning_unciphered = false;
|
||||
}
|
||||
|
||||
current_mkey = document.getElementById("master_key").value;
|
||||
|
||||
if (current_mkey != "")
|
||||
current_mkey = derive_mkey(current_user, current_mkey);
|
||||
else
|
||||
// Disable warning on empty master key (clear passwords from others)
|
||||
warning_unciphered = false;
|
||||
|
||||
change_master_key(warning_unciphered);
|
||||
}
|
||||
|
||||
function start()
|
||||
{
|
||||
select_widget = document.getElementById('selected_user') ;
|
||||
|
||||
if (select_widget == null) return;
|
||||
|
||||
return update_master_key(false);
|
||||
}
|
||||
|
||||
function add_password_server(user, pentry)
|
||||
{
|
||||
var ok = false;
|
||||
req = new XMLHttpRequest();
|
||||
req.addEventListener("load", function(evt) {
|
||||
resp = this.responseText;
|
||||
if (resp == "OK")
|
||||
ok = true;
|
||||
else
|
||||
alert(resp);
|
||||
}, false);
|
||||
req.open("POST", document.documentURI, false);
|
||||
req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
|
||||
req.send("add_entry=1&user=" + user + "&login=" + pentry.ciphered_login + "&password=" + pentry.ciphered_password);
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
function construct_pentry(user, url, password, login, mkey, derive_masterkey)
|
||||
{
|
||||
var ret = null;
|
||||
|
||||
if (url == "")
|
||||
{
|
||||
alert("URL is empty");
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (login == "")
|
||||
{
|
||||
alert("Login is empty");
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (password == "")
|
||||
{
|
||||
alert("Password is empty");
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (mkey == "")
|
||||
{
|
||||
alert("Master key is empty");
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (derive_masterkey)
|
||||
mkey = derive_mkey(current_user, mkey);
|
||||
|
||||
for(i=0; i<passwords.length; i++)
|
||||
{
|
||||
p = passwords[i];
|
||||
if (p.clear_url == url &&
|
||||
p.clear_password == password &&
|
||||
p.clear_login == login &&
|
||||
p.masterkey == mkey)
|
||||
{
|
||||
alert("Entry already exists");
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
ciphered_login = "@@" + url + ";" + login;
|
||||
|
||||
// Add salt
|
||||
for(i=0; i<3; i++)
|
||||
{
|
||||
password += String.fromCharCode((Math.random() * 128)+1);
|
||||
}
|
||||
|
||||
ciphered_password = password;
|
||||
|
||||
aes = new AES();
|
||||
a_masterkey = aes.init(hex2a(mkey));
|
||||
ciphered_login = a2hex(aes.encryptLongString(ciphered_login, a_masterkey));
|
||||
ciphered_password = a2hex(aes.encryptLongString(ciphered_password, a_masterkey));
|
||||
|
||||
pentry = new PasswordEntry(ciphered_login, ciphered_password);
|
||||
pentry.unciphered = true;
|
||||
pentry.clear_url = url;
|
||||
pentry.clear_login = login;
|
||||
pentry.clear_password = password.substr(0, password.length-3);
|
||||
pentry.masterkey = mkey;
|
||||
|
||||
return pentry;
|
||||
}
|
||||
|
||||
function remove_password_server(user, login)
|
||||
{
|
||||
var ok = false;
|
||||
|
||||
req = new XMLHttpRequest();
|
||||
req.addEventListener("load", function(evt) {
|
||||
resp = this.responseText;
|
||||
if (resp == "OK")
|
||||
ok = true;
|
||||
else
|
||||
alert(resp);
|
||||
}, false);
|
||||
req.open("POST", document.documentURI, false);
|
||||
req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
|
||||
req.send("delete_entry=1&user=" + user + "&login=" + login);
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
function add_password()
|
||||
{
|
||||
var url = "";
|
||||
var login = "";
|
||||
var password = "";
|
||||
var mkey = "";
|
||||
|
||||
div = document.getElementById("add_new_password");
|
||||
|
||||
inputs = div.getElementsByTagName("input");
|
||||
|
||||
for(i=0; i<inputs.length; i++)
|
||||
{
|
||||
if (inputs[i].getAttribute("name") == "url")
|
||||
url = url_domain(inputs[i].value);
|
||||
else if (inputs[i].getAttribute("name") == "login")
|
||||
login = inputs[i].value.trim();
|
||||
else if (inputs[i].getAttribute("name") == "password")
|
||||
password = inputs[i].value.trim();
|
||||
else if (inputs[i].getAttribute("name") == "mkey")
|
||||
mkey = inputs[i].value;
|
||||
}
|
||||
|
||||
pentry = construct_pentry(current_user, url, password, login, mkey, true)
|
||||
|
||||
if (pentry == null) return;
|
||||
|
||||
res = add_password_server(current_user, pentry);
|
||||
|
||||
if (!res) return false;
|
||||
|
||||
current_mkey = pentry.masterkey;
|
||||
|
||||
passwords.push(pentry);
|
||||
|
||||
change_master_key(false);
|
||||
|
||||
for(i=0; i<inputs.length; i++)
|
||||
{
|
||||
if (inputs[i].getAttribute("type") == "text" ||
|
||||
inputs[i].getAttribute("type") == "password")
|
||||
inputs[i].value = "";
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function delete_entry(entry_number)
|
||||
{
|
||||
entry = document.getElementById(entry_number);
|
||||
|
||||
if (entry == null) {
|
||||
alert(entry_number + " not found");
|
||||
return;
|
||||
}
|
||||
|
||||
inputs = entry.getElementsByTagName("input");
|
||||
|
||||
var ciphered_login = null;
|
||||
for(i=0; i<inputs.length; i++)
|
||||
{
|
||||
if (inputs[i].getAttribute("name") == "ciphered_login")
|
||||
{
|
||||
ciphered_login = inputs[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ciphered_login == null)
|
||||
{
|
||||
alert("Widget not found");
|
||||
return;
|
||||
}
|
||||
|
||||
var found = -1;
|
||||
for(i=0; i<passwords.length; i++)
|
||||
{
|
||||
if (passwords[i].ciphered_login == ciphered_login.getAttribute("login"))
|
||||
{
|
||||
found = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (found == -1)
|
||||
{
|
||||
alert("Password not found int database");
|
||||
return;
|
||||
}
|
||||
|
||||
if(!confirm("Are you sure want to delete this entry ?"))
|
||||
return;
|
||||
|
||||
ok = remove_password_server(current_user, ciphered_login.getAttribute("login"));
|
||||
|
||||
if (!ok) return;
|
||||
|
||||
parent = ciphered_login.parentNode;
|
||||
parent.removeAllChilds();
|
||||
|
||||
passwords.remove(found);
|
||||
|
||||
update_stats();
|
||||
}
|
||||
|
||||
function update_entry(entry_number)
|
||||
{
|
||||
var url = "";
|
||||
var login = "";
|
||||
var password = "";
|
||||
var mkey = "";
|
||||
var ciphered_login;
|
||||
|
||||
entry = document.getElementById(entry_number);
|
||||
|
||||
if (entry == null) {
|
||||
alert(entry_number + " not found");
|
||||
return;
|
||||
}
|
||||
|
||||
inputs = entry.getElementsByTagName("input");
|
||||
|
||||
var ciphered_login = null;
|
||||
for(i=0; i<inputs.length; i++)
|
||||
{
|
||||
if (inputs[i].getAttribute("name") == "url")
|
||||
url = url_domain(inputs[i].value);
|
||||
else if (inputs[i].getAttribute("name") == "login")
|
||||
login = inputs[i].value.trim();
|
||||
else if (inputs[i].getAttribute("name") == "password")
|
||||
password = inputs[i].value.trim();
|
||||
else if (inputs[i].getAttribute("name") == "ciphered_login")
|
||||
ciphered_login = inputs[i];
|
||||
}
|
||||
|
||||
var found = -1;
|
||||
for(i=0; i<passwords.length; i++)
|
||||
{
|
||||
if (passwords[i].ciphered_login == ciphered_login.getAttribute("login"))
|
||||
{
|
||||
found = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (found == -1)
|
||||
{
|
||||
alert("Password not found int database");
|
||||
return;
|
||||
}
|
||||
|
||||
if(!confirm("Are you sure want to update this entry ?"))
|
||||
return;
|
||||
|
||||
pentry = construct_pentry(current_user, url, password, login, current_mkey, false);
|
||||
|
||||
if (pentry == null) return;
|
||||
|
||||
ok = remove_password_server(current_user, passwords[found].ciphered_login);
|
||||
if (!ok) return;
|
||||
|
||||
ok = add_password_server(current_user, pentry);
|
||||
if (!ok) return;
|
||||
|
||||
passwords[found] = pentry;
|
||||
ciphered_login.setAttribute("login", pentry.ciphered_login);
|
||||
|
||||
alert("Entry updated");
|
||||
}
|
BIN
server/resources/gpass.png
Executable file
BIN
server/resources/gpass.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
46
server/resources/hmac.js
Normal file
46
server/resources/hmac.js
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
Copyright (C) 2013 Grégory Soutadé
|
||||
|
||||
This file is part of gPass.
|
||||
|
||||
gPass is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
gPass is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with gPass. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
function hmac256(key, message) {
|
||||
var ipad = "";
|
||||
var opad = "";
|
||||
|
||||
if (key.length > 512/8)
|
||||
{
|
||||
key = digest256(key);
|
||||
}
|
||||
|
||||
for(i=0; i<512/8; i++)
|
||||
{
|
||||
if (i >= key.length)
|
||||
{
|
||||
ipad += String.fromCharCode(0x36);
|
||||
opad += String.fromCharCode(0x5c);
|
||||
}
|
||||
else
|
||||
{
|
||||
ipad += String.fromCharCode(key.charCodeAt(i) ^ 0x36);
|
||||
opad += String.fromCharCode(key.charCodeAt(i) ^ 0x5c);
|
||||
}
|
||||
}
|
||||
|
||||
result = digest256(opad + digest256(ipad + message));
|
||||
|
||||
return result;
|
||||
}
|
291
server/resources/jsaes.js
Normal file
291
server/resources/jsaes.js
Normal file
@@ -0,0 +1,291 @@
|
||||
/*
|
||||
* jsaes version 0.1 - Copyright 2006 B. Poettering
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
* 02111-1307 USA
|
||||
*/
|
||||
|
||||
/*
|
||||
* http://point-at-infinity.org/jsaes/
|
||||
*
|
||||
* This is a javascript implementation of the AES block cipher. Key lengths
|
||||
* of 128, 192 and 256 bits are supported.
|
||||
*
|
||||
* The well-functioning of the encryption/decryption routines has been
|
||||
* verified for different key lengths with the test vectors given in
|
||||
* FIPS-197, Appendix C.
|
||||
*
|
||||
* The following code example enciphers the plaintext block '00 11 22 .. EE FF'
|
||||
* with the 256 bit key '00 01 02 .. 1E 1F'.
|
||||
*
|
||||
* AES_Init();
|
||||
*
|
||||
* var block = new Array(16);
|
||||
* for(var i = 0; i < 16; i++)
|
||||
* block[i] = 0x11 * i;
|
||||
*
|
||||
* var key = new Array(32);
|
||||
* for(var i = 0; i < 32; i++)
|
||||
* key[i] = i;
|
||||
*
|
||||
* AES_ExpandKey(key);
|
||||
* AES_Encrypt(block, key);
|
||||
*
|
||||
* AES_Done();
|
||||
*
|
||||
* Report bugs to: jsaes AT point-at-infinity.org
|
||||
*
|
||||
*/
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
/*
|
||||
AES_Init: initialize the tables needed at runtime. Call this function
|
||||
before the (first) key expansion.
|
||||
*/
|
||||
|
||||
function AES_Init() {
|
||||
AES_Sbox_Inv = new Array(256);
|
||||
for(var i = 0; i < 256; i++)
|
||||
AES_Sbox_Inv[AES_Sbox[i]] = i;
|
||||
|
||||
AES_ShiftRowTab_Inv = new Array(16);
|
||||
for(var i = 0; i < 16; i++)
|
||||
AES_ShiftRowTab_Inv[AES_ShiftRowTab[i]] = i;
|
||||
|
||||
AES_xtime = new Array(256);
|
||||
for(var i = 0; i < 128; i++) {
|
||||
AES_xtime[i] = i << 1;
|
||||
AES_xtime[128 + i] = (i << 1) ^ 0x1b;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
AES_Done: release memory reserved by AES_Init. Call this function after
|
||||
the last encryption/decryption operation.
|
||||
*/
|
||||
|
||||
function AES_Done() {
|
||||
delete AES_Sbox_Inv;
|
||||
delete AES_ShiftRowTab_Inv;
|
||||
delete AES_xtime;
|
||||
}
|
||||
|
||||
/*
|
||||
AES_ExpandKey: expand a cipher key. Depending on the desired encryption
|
||||
strength of 128, 192 or 256 bits 'key' has to be a byte array of length
|
||||
16, 24 or 32, respectively. The key expansion is done "in place", meaning
|
||||
that the array 'key' is modified.
|
||||
*/
|
||||
|
||||
function AES_ExpandKey(key) {
|
||||
var kl = key.length, ks, Rcon = 1;
|
||||
switch (kl) {
|
||||
case 16: ks = 16 * (10 + 1); break;
|
||||
case 24: ks = 16 * (12 + 1); break;
|
||||
case 32: ks = 16 * (14 + 1); break;
|
||||
default:
|
||||
alert("AES_ExpandKey: Only key lengths of 16, 24 or 32 bytes allowed!");
|
||||
}
|
||||
for(var i = kl; i < ks; i += 4) {
|
||||
var temp = key.slice(i - 4, i);
|
||||
if (i % kl == 0) {
|
||||
temp = new Array(AES_Sbox[temp[1]] ^ Rcon, AES_Sbox[temp[2]],
|
||||
AES_Sbox[temp[3]], AES_Sbox[temp[0]]);
|
||||
if ((Rcon <<= 1) >= 256)
|
||||
Rcon ^= 0x11b;
|
||||
}
|
||||
else if ((kl > 24) && (i % kl == 16))
|
||||
temp = new Array(AES_Sbox[temp[0]], AES_Sbox[temp[1]],
|
||||
AES_Sbox[temp[2]], AES_Sbox[temp[3]]);
|
||||
for(var j = 0; j < 4; j++)
|
||||
key[i + j] = key[i + j - kl] ^ temp[j];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
AES_Encrypt: encrypt the 16 byte array 'block' with the previously
|
||||
expanded key 'key'.
|
||||
*/
|
||||
|
||||
function AES_Encrypt(block, key) {
|
||||
var l = key.length;
|
||||
AES_AddRoundKey(block, key.slice(0, 16));
|
||||
for(var i = 16; i < l - 16; i += 16) {
|
||||
AES_SubBytes(block, AES_Sbox);
|
||||
AES_ShiftRows(block, AES_ShiftRowTab);
|
||||
AES_MixColumns(block);
|
||||
AES_AddRoundKey(block, key.slice(i, i + 16));
|
||||
}
|
||||
AES_SubBytes(block, AES_Sbox);
|
||||
AES_ShiftRows(block, AES_ShiftRowTab);
|
||||
AES_AddRoundKey(block, key.slice(i, l));
|
||||
}
|
||||
|
||||
/*
|
||||
AES_Decrypt: decrypt the 16 byte array 'block' with the previously
|
||||
expanded key 'key'.
|
||||
*/
|
||||
|
||||
function AES_Decrypt(block, key) {
|
||||
var l = key.length;
|
||||
AES_AddRoundKey(block, key.slice(l - 16, l));
|
||||
AES_ShiftRows(block, AES_ShiftRowTab_Inv);
|
||||
AES_SubBytes(block, AES_Sbox_Inv);
|
||||
for(var i = l - 32; i >= 16; i -= 16) {
|
||||
AES_AddRoundKey(block, key.slice(i, i + 16));
|
||||
AES_MixColumns_Inv(block);
|
||||
AES_ShiftRows(block, AES_ShiftRowTab_Inv);
|
||||
AES_SubBytes(block, AES_Sbox_Inv);
|
||||
}
|
||||
AES_AddRoundKey(block, key.slice(0, 16));
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
/* The following lookup tables and functions are for internal use only! */
|
||||
|
||||
AES_Sbox = new Array(99,124,119,123,242,107,111,197,48,1,103,43,254,215,171,
|
||||
118,202,130,201,125,250,89,71,240,173,212,162,175,156,164,114,192,183,253,
|
||||
147,38,54,63,247,204,52,165,229,241,113,216,49,21,4,199,35,195,24,150,5,154,
|
||||
7,18,128,226,235,39,178,117,9,131,44,26,27,110,90,160,82,59,214,179,41,227,
|
||||
47,132,83,209,0,237,32,252,177,91,106,203,190,57,74,76,88,207,208,239,170,
|
||||
251,67,77,51,133,69,249,2,127,80,60,159,168,81,163,64,143,146,157,56,245,
|
||||
188,182,218,33,16,255,243,210,205,12,19,236,95,151,68,23,196,167,126,61,
|
||||
100,93,25,115,96,129,79,220,34,42,144,136,70,238,184,20,222,94,11,219,224,
|
||||
50,58,10,73,6,36,92,194,211,172,98,145,149,228,121,231,200,55,109,141,213,
|
||||
78,169,108,86,244,234,101,122,174,8,186,120,37,46,28,166,180,198,232,221,
|
||||
116,31,75,189,139,138,112,62,181,102,72,3,246,14,97,53,87,185,134,193,29,
|
||||
158,225,248,152,17,105,217,142,148,155,30,135,233,206,85,40,223,140,161,
|
||||
137,13,191,230,66,104,65,153,45,15,176,84,187,22);
|
||||
|
||||
AES_ShiftRowTab = new Array(0,5,10,15,4,9,14,3,8,13,2,7,12,1,6,11);
|
||||
|
||||
function AES_SubBytes(state, sbox) {
|
||||
for(var i = 0; i < 16; i++)
|
||||
state[i] = sbox[state[i]];
|
||||
}
|
||||
|
||||
function AES_AddRoundKey(state, rkey) {
|
||||
for(var i = 0; i < 16; i++)
|
||||
state[i] ^= rkey[i];
|
||||
}
|
||||
|
||||
function AES_ShiftRows(state, shifttab) {
|
||||
var h = new Array().concat(state);
|
||||
for(var i = 0; i < 16; i++)
|
||||
state[i] = h[shifttab[i]];
|
||||
}
|
||||
|
||||
function AES_MixColumns(state) {
|
||||
for(var i = 0; i < 16; i += 4) {
|
||||
var s0 = state[i + 0], s1 = state[i + 1];
|
||||
var s2 = state[i + 2], s3 = state[i + 3];
|
||||
var h = s0 ^ s1 ^ s2 ^ s3;
|
||||
state[i + 0] ^= h ^ AES_xtime[s0 ^ s1];
|
||||
state[i + 1] ^= h ^ AES_xtime[s1 ^ s2];
|
||||
state[i + 2] ^= h ^ AES_xtime[s2 ^ s3];
|
||||
state[i + 3] ^= h ^ AES_xtime[s3 ^ s0];
|
||||
}
|
||||
}
|
||||
|
||||
function AES_MixColumns_Inv(state) {
|
||||
for(var i = 0; i < 16; i += 4) {
|
||||
var s0 = state[i + 0], s1 = state[i + 1];
|
||||
var s2 = state[i + 2], s3 = state[i + 3];
|
||||
var h = s0 ^ s1 ^ s2 ^ s3;
|
||||
var xh = AES_xtime[h];
|
||||
var h1 = AES_xtime[AES_xtime[xh ^ s0 ^ s2]] ^ h;
|
||||
var h2 = AES_xtime[AES_xtime[xh ^ s1 ^ s3]] ^ h;
|
||||
state[i + 0] ^= h1 ^ AES_xtime[s0 ^ s1];
|
||||
state[i + 1] ^= h2 ^ AES_xtime[s1 ^ s2];
|
||||
state[i + 2] ^= h1 ^ AES_xtime[s2 ^ s3];
|
||||
state[i + 3] ^= h2 ^ AES_xtime[s3 ^ s0];
|
||||
}
|
||||
}
|
||||
|
||||
function bin2String (array) {
|
||||
var result = "";
|
||||
for (var i = 0; i < array.length; i++) {
|
||||
result += String.fromCharCode(parseInt(array[i], 2));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function string2Bin (str) {
|
||||
var result = [];
|
||||
for (var i = 0; i < str.length; i++) {
|
||||
result.push(str.charCodeAt(i));
|
||||
}
|
||||
while ((result.length % 16))
|
||||
result.push(0);
|
||||
return result;
|
||||
}
|
||||
|
||||
function bin2String (array) {
|
||||
return String.fromCharCode.apply(String, array);
|
||||
}
|
||||
|
||||
// http://osama-oransa.blogspot.fr/2012/03/using-aes-encrypting-in-java-script.html
|
||||
function AES(a) {
|
||||
this.init = function (myKey){
|
||||
AES_Init();
|
||||
var key = string2Bin(myKey);
|
||||
AES_ExpandKey(key);
|
||||
return key;
|
||||
}
|
||||
|
||||
this.encrypt = function ( inputStr,key ) {
|
||||
var block = string2Bin(inputStr);
|
||||
AES_Encrypt(block, key);
|
||||
var data=bin2String(block);
|
||||
return data;
|
||||
}
|
||||
|
||||
this.decrypt = function ( inputStr,key ) {
|
||||
block = string2Bin(inputStr);
|
||||
AES_Decrypt(block, key);
|
||||
var data=bin2String(block);
|
||||
return data;
|
||||
}
|
||||
|
||||
this.encryptLongString = function( myString,key ) {
|
||||
if(myString.length>16){
|
||||
var data='';
|
||||
for(var i=0;i<myString.length;i=i+16){
|
||||
data+=this.encrypt(myString.substr(i,16),key);
|
||||
}
|
||||
return data;
|
||||
}else{
|
||||
return this.encrypt(myString,key);
|
||||
}
|
||||
}
|
||||
|
||||
this.decryptLongString = function ( myString,key ) {
|
||||
if(myString.length>16){
|
||||
var data='';
|
||||
for(var i=0;i<myString.length;i=i+16){
|
||||
data+=this.decrypt(myString.substr(i,16),key);
|
||||
}
|
||||
return data;
|
||||
}else{
|
||||
return this.decrypt(myString,key);
|
||||
}
|
||||
}
|
||||
|
||||
this.finish = function(){
|
||||
AES_Done();
|
||||
}
|
||||
}
|
261
server/resources/jssha256.js
Normal file
261
server/resources/jssha256.js
Normal file
@@ -0,0 +1,261 @@
|
||||
/*
|
||||
* A JavaScript implementation of the SHA256 hash function.
|
||||
*
|
||||
* FILE: sha256.js
|
||||
* VERSION: 0.8
|
||||
* AUTHOR: Christoph Bichlmeier <informatik@zombiearena.de>
|
||||
*
|
||||
* NOTE: This version is not tested thoroughly!
|
||||
*
|
||||
* Copyright (c) 2003, Christoph Bichlmeier
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* ======================================================================
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/* SHA256 logical functions */
|
||||
function rotateRight(n,x) {
|
||||
return ((x >>> n) | (x << (32 - n)));
|
||||
}
|
||||
function choice(x,y,z) {
|
||||
return ((x & y) ^ (~x & z));
|
||||
}
|
||||
function majority(x,y,z) {
|
||||
return ((x & y) ^ (x & z) ^ (y & z));
|
||||
}
|
||||
function sha256_Sigma0(x) {
|
||||
return (rotateRight(2, x) ^ rotateRight(13, x) ^ rotateRight(22, x));
|
||||
}
|
||||
function sha256_Sigma1(x) {
|
||||
return (rotateRight(6, x) ^ rotateRight(11, x) ^ rotateRight(25, x));
|
||||
}
|
||||
function sha256_sigma0(x) {
|
||||
return (rotateRight(7, x) ^ rotateRight(18, x) ^ (x >>> 3));
|
||||
}
|
||||
function sha256_sigma1(x) {
|
||||
return (rotateRight(17, x) ^ rotateRight(19, x) ^ (x >>> 10));
|
||||
}
|
||||
function sha256_expand(W, j) {
|
||||
return (W[j&0x0f] += sha256_sigma1(W[(j+14)&0x0f]) + W[(j+9)&0x0f] +
|
||||
sha256_sigma0(W[(j+1)&0x0f]));
|
||||
}
|
||||
|
||||
/* Hash constant words K: */
|
||||
var K256 = new Array(
|
||||
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
|
||||
0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
||||
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
|
||||
0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
||||
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
|
||||
0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
||||
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
|
||||
0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
||||
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
|
||||
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
||||
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
|
||||
0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
||||
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
|
||||
0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
||||
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
|
||||
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
||||
);
|
||||
|
||||
/* global arrays */
|
||||
var ihash, count, buffer;
|
||||
var sha256_hex_digits = "0123456789abcdef";
|
||||
|
||||
/* Add 32-bit integers with 16-bit operations (bug in some JS-interpreters:
|
||||
overflow) */
|
||||
function safe_add(x, y)
|
||||
{
|
||||
var lsw = (x & 0xffff) + (y & 0xffff);
|
||||
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
|
||||
return (msw << 16) | (lsw & 0xffff);
|
||||
}
|
||||
|
||||
/* Initialise the SHA256 computation */
|
||||
function sha256_init() {
|
||||
ihash = new Array(8);
|
||||
count = new Array(2);
|
||||
buffer = new Array(64);
|
||||
count[0] = count[1] = 0;
|
||||
ihash[0] = 0x6a09e667;
|
||||
ihash[1] = 0xbb67ae85;
|
||||
ihash[2] = 0x3c6ef372;
|
||||
ihash[3] = 0xa54ff53a;
|
||||
ihash[4] = 0x510e527f;
|
||||
ihash[5] = 0x9b05688c;
|
||||
ihash[6] = 0x1f83d9ab;
|
||||
ihash[7] = 0x5be0cd19;
|
||||
}
|
||||
|
||||
/* Transform a 512-bit message block */
|
||||
function sha256_transform() {
|
||||
var a, b, c, d, e, f, g, h, T1, T2;
|
||||
var W = new Array(16);
|
||||
|
||||
/* Initialize registers with the previous intermediate value */
|
||||
a = ihash[0];
|
||||
b = ihash[1];
|
||||
c = ihash[2];
|
||||
d = ihash[3];
|
||||
e = ihash[4];
|
||||
f = ihash[5];
|
||||
g = ihash[6];
|
||||
h = ihash[7];
|
||||
|
||||
/* make 32-bit words */
|
||||
for(var i=0; i<16; i++)
|
||||
W[i] = ((buffer[(i<<2)+3]) | (buffer[(i<<2)+2] << 8) | (buffer[(i<<2)+1]
|
||||
<< 16) | (buffer[i<<2] << 24));
|
||||
|
||||
for(var j=0; j<64; j++) {
|
||||
T1 = h + sha256_Sigma1(e) + choice(e, f, g) + K256[j];
|
||||
if(j < 16) T1 += W[j];
|
||||
else T1 += sha256_expand(W, j);
|
||||
T2 = sha256_Sigma0(a) + majority(a, b, c);
|
||||
h = g;
|
||||
g = f;
|
||||
f = e;
|
||||
e = safe_add(d, T1);
|
||||
d = c;
|
||||
c = b;
|
||||
b = a;
|
||||
a = safe_add(T1, T2);
|
||||
}
|
||||
|
||||
/* Compute the current intermediate hash value */
|
||||
ihash[0] += a;
|
||||
ihash[1] += b;
|
||||
ihash[2] += c;
|
||||
ihash[3] += d;
|
||||
ihash[4] += e;
|
||||
ihash[5] += f;
|
||||
ihash[6] += g;
|
||||
ihash[7] += h;
|
||||
}
|
||||
|
||||
/* Read the next chunk of data and update the SHA256 computation */
|
||||
function sha256_update(data, inputLen) {
|
||||
var i, index, curpos = 0;
|
||||
/* Compute number of bytes mod 64 */
|
||||
index = ((count[0] >> 3) & 0x3f);
|
||||
var remainder = (inputLen & 0x3f);
|
||||
|
||||
/* Update number of bits */
|
||||
if ((count[0] += (inputLen << 3)) < (inputLen << 3)) count[1]++;
|
||||
count[1] += (inputLen >> 29);
|
||||
|
||||
/* Transform as many times as possible */
|
||||
for(i=0; i+63<inputLen; i+=64) {
|
||||
for(var j=index; j<64; j++)
|
||||
buffer[j] = data.charCodeAt(curpos++);
|
||||
sha256_transform();
|
||||
index = 0;
|
||||
}
|
||||
|
||||
/* Buffer remaining input */
|
||||
for(var j=0; j<remainder; j++)
|
||||
buffer[j] = data.charCodeAt(curpos++);
|
||||
}
|
||||
|
||||
/* Finish the computation by operations such as padding */
|
||||
function sha256_final() {
|
||||
var index = ((count[0] >> 3) & 0x3f);
|
||||
buffer[index++] = 0x80;
|
||||
if(index <= 56) {
|
||||
for(var i=index; i<56; i++)
|
||||
buffer[i] = 0;
|
||||
} else {
|
||||
for(var i=index; i<64; i++)
|
||||
buffer[i] = 0;
|
||||
sha256_transform();
|
||||
for(var i=0; i<56; i++)
|
||||
buffer[i] = 0;
|
||||
}
|
||||
buffer[56] = (count[1] >>> 24) & 0xff;
|
||||
buffer[57] = (count[1] >>> 16) & 0xff;
|
||||
buffer[58] = (count[1] >>> 8) & 0xff;
|
||||
buffer[59] = count[1] & 0xff;
|
||||
buffer[60] = (count[0] >>> 24) & 0xff;
|
||||
buffer[61] = (count[0] >>> 16) & 0xff;
|
||||
buffer[62] = (count[0] >>> 8) & 0xff;
|
||||
buffer[63] = count[0] & 0xff;
|
||||
sha256_transform();
|
||||
}
|
||||
|
||||
/* Split the internal hash values into an array of bytes */
|
||||
function sha256_encode_bytes() {
|
||||
var j=0;
|
||||
var output = new Array(32);
|
||||
for(var i=0; i<8; i++) {
|
||||
output[j++] = ((ihash[i] >>> 24) & 0xff);
|
||||
output[j++] = ((ihash[i] >>> 16) & 0xff);
|
||||
output[j++] = ((ihash[i] >>> 8) & 0xff);
|
||||
output[j++] = (ihash[i] & 0xff);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
/* Get the internal hash as a hex string */
|
||||
function sha256_encode_hex() {
|
||||
var output = new String();
|
||||
for(var i=0; i<8; i++) {
|
||||
for(var j=28; j>=0; j-=4)
|
||||
output += sha256_hex_digits.charAt((ihash[i] >>> j) & 0x0f);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
/* Get the internal hash as string */
|
||||
function sha256_encode() {
|
||||
var output = new String();
|
||||
for(var i=0; i<8; i++) {
|
||||
for(var j=3; j>=0; j--)
|
||||
output += String.fromCharCode((ihash[i] >>> j*8) & 0xff);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
/* Main function: returns a hex string representing the SHA256 value of the
|
||||
given data */
|
||||
function digest256 (data) {
|
||||
sha256_init();
|
||||
sha256_update(data, data.length);
|
||||
sha256_final();
|
||||
return sha256_encode();
|
||||
// return sha256_encode_hex();
|
||||
}
|
||||
|
||||
/* test if the JS-interpreter is working properly */
|
||||
function sha256_self_test()
|
||||
{
|
||||
return sha256_digest("message digest") ==
|
||||
"f7846f55cf23e14eebeab5b4e1550cad5b509e3348fbc4efa3a1413d393cb650";
|
||||
}
|
||||
|
||||
|
32
server/resources/parseuri.js
Executable file
32
server/resources/parseuri.js
Executable file
@@ -0,0 +1,32 @@
|
||||
// parseUri 1.2.2
|
||||
// (c) Steven Levithan <stevenlevithan.com>
|
||||
// MIT License
|
||||
|
||||
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*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
|
||||
}
|
||||
};
|
51
server/resources/pkdbf2.js
Normal file
51
server/resources/pkdbf2.js
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
Copyright (C) 2013 Grégory Soutadé
|
||||
|
||||
This file is part of gPass.
|
||||
|
||||
gPass is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
gPass is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with gPass. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
function pkdbf2 (password, salt, iterations, outlen) {
|
||||
var result = "";
|
||||
var temp = "";
|
||||
var temp2 = "";
|
||||
var temp_res = "";
|
||||
var temp_res2 = "";
|
||||
|
||||
for (i=1; result.length < outlen; i++)
|
||||
{
|
||||
temp = hmac256(password, salt +
|
||||
String.fromCharCode((i & 0xff000000) >> 24) +
|
||||
String.fromCharCode((i & 0x00ff0000) >> 16) +
|
||||
String.fromCharCode((i & 0x0000ff00) >> 8) +
|
||||
String.fromCharCode((i & 0x000000ff) >> 0)
|
||||
);
|
||||
temp_res = temp;
|
||||
|
||||
for(a=1; a<iterations; a++)
|
||||
{
|
||||
temp2 = hmac256(password, temp);
|
||||
temp_res2 = "";
|
||||
for(b = 0; b<temp_res.length; b++)
|
||||
temp_res2 += String.fromCharCode(temp_res.charCodeAt(b) ^ temp2.charCodeAt(b));
|
||||
temp_res = temp_res2;
|
||||
temp = temp2;
|
||||
}
|
||||
|
||||
result += temp_res;
|
||||
}
|
||||
|
||||
return result.substr(0, outlen);
|
||||
}
|
341
server/resources/pwdmeter.js
Normal file
341
server/resources/pwdmeter.js
Normal file
@@ -0,0 +1,341 @@
|
||||
/*
|
||||
** Created by: Jeff Todnem (http://www.todnem.com/)
|
||||
** Created on: 2007-08-14
|
||||
** Last modified: 2010-05-03
|
||||
**
|
||||
** License Information:
|
||||
** -------------------------------------------------------------------------
|
||||
** Copyright (C) 2007 Jeff Todnem
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the GNU General Public License as published by the
|
||||
** Free Software Foundation; either version 2 of the License, or (at your
|
||||
** option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful, but
|
||||
** WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
** General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License along
|
||||
** with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
** 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
**
|
||||
*/
|
||||
|
||||
function addLoadEvent(func) {
|
||||
var oldonload = window.onload;
|
||||
if (typeof window.onload != "function") {
|
||||
window.onload = func;
|
||||
}
|
||||
else {
|
||||
window.onload = function() {
|
||||
if (oldonload) {
|
||||
oldonload();
|
||||
}
|
||||
func();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function $() {
|
||||
var arrElms = [];
|
||||
for (var i=0; i < arguments.length; i++) {
|
||||
var elm = arguments[i];
|
||||
if (typeof(elm == "string")) { elm = document.getElementById(elm); }
|
||||
if (arguments.length == 1) { return elm; }
|
||||
arrElms.push(elm);
|
||||
}
|
||||
return arrElms;
|
||||
}
|
||||
|
||||
String.prototype.strReverse = function() {
|
||||
var newstring = "";
|
||||
for (var s=0; s < this.length; s++) {
|
||||
newstring = this.charAt(s) + newstring;
|
||||
}
|
||||
return newstring;
|
||||
//strOrig = ' texttotrim ';
|
||||
//strReversed = strOrig.revstring();
|
||||
};
|
||||
|
||||
function chkPass(pwd) {
|
||||
var oScorebar = $("scorebar");
|
||||
var oScore = $("score");
|
||||
var oComplexity = $("complexity");
|
||||
// Simultaneous variable declaration and value assignment aren't supported in IE apparently
|
||||
// so I'm forced to assign the same value individually per var to support a crappy browser *sigh*
|
||||
var nScore=0, nLength=0, nAlphaUC=0, nAlphaLC=0, nNumber=0, nSymbol=0, nMidChar=0, nRequirements=0, nAlphasOnly=0, nNumbersOnly=0, nUnqChar=0, nRepChar=0, nRepInc=0, nConsecAlphaUC=0, nConsecAlphaLC=0, nConsecNumber=0, nConsecSymbol=0, nConsecCharType=0, nSeqAlpha=0, nSeqNumber=0, nSeqSymbol=0, nSeqChar=0, nReqChar=0, nMultConsecCharType=0;
|
||||
var nMultRepChar=1, nMultConsecSymbol=1;
|
||||
var nMultMidChar=2, nMultRequirements=2, nMultConsecAlphaUC=2, nMultConsecAlphaLC=2, nMultConsecNumber=2;
|
||||
var nReqCharType=3, nMultAlphaUC=3, nMultAlphaLC=3, nMultSeqAlpha=3, nMultSeqNumber=3, nMultSeqSymbol=3;
|
||||
var nMultLength=4, nMultNumber=4;
|
||||
var nMultSymbol=6;
|
||||
var nTmpAlphaUC="", nTmpAlphaLC="", nTmpNumber="", nTmpSymbol="";
|
||||
var sAlphaUC="0", sAlphaLC="0", sNumber="0", sSymbol="0", sMidChar="0", sRequirements="0", sAlphasOnly="0", sNumbersOnly="0", sRepChar="0", sConsecAlphaUC="0", sConsecAlphaLC="0", sConsecNumber="0", sSeqAlpha="0", sSeqNumber="0", sSeqSymbol="0";
|
||||
var sAlphas = "abcdefghijklmnopqrstuvwxyz";
|
||||
var sNumerics = "01234567890";
|
||||
var sSymbols = ")!@#$%^&*()";
|
||||
var sComplexity = "Too Short";
|
||||
var sStandards = "Below";
|
||||
var nMinPwdLen = 8;
|
||||
if (document.all) { var nd = 0; } else { var nd = 1; }
|
||||
if (pwd) {
|
||||
nScore = parseInt(pwd.length * nMultLength);
|
||||
nLength = pwd.length;
|
||||
var arrPwd = pwd.replace(/\s+/g,"").split(/\s*/);
|
||||
var arrPwdLen = arrPwd.length;
|
||||
|
||||
/* Loop through password to check for Symbol, Numeric, Lowercase and Uppercase pattern matches */
|
||||
for (var a=0; a < arrPwdLen; a++) {
|
||||
if (arrPwd[a].match(/[A-Z]/g)) {
|
||||
if (nTmpAlphaUC !== "") { if ((nTmpAlphaUC + 1) == a) { nConsecAlphaUC++; nConsecCharType++; } }
|
||||
nTmpAlphaUC = a;
|
||||
nAlphaUC++;
|
||||
}
|
||||
else if (arrPwd[a].match(/[a-z]/g)) {
|
||||
if (nTmpAlphaLC !== "") { if ((nTmpAlphaLC + 1) == a) { nConsecAlphaLC++; nConsecCharType++; } }
|
||||
nTmpAlphaLC = a;
|
||||
nAlphaLC++;
|
||||
}
|
||||
else if (arrPwd[a].match(/[0-9]/g)) {
|
||||
if (a > 0 && a < (arrPwdLen - 1)) { nMidChar++; }
|
||||
if (nTmpNumber !== "") { if ((nTmpNumber + 1) == a) { nConsecNumber++; nConsecCharType++; } }
|
||||
nTmpNumber = a;
|
||||
nNumber++;
|
||||
}
|
||||
else if (arrPwd[a].match(/[^a-zA-Z0-9_]/g)) {
|
||||
if (a > 0 && a < (arrPwdLen - 1)) { nMidChar++; }
|
||||
if (nTmpSymbol !== "") { if ((nTmpSymbol + 1) == a) { nConsecSymbol++; nConsecCharType++; } }
|
||||
nTmpSymbol = a;
|
||||
nSymbol++;
|
||||
}
|
||||
/* Internal loop through password to check for repeat characters */
|
||||
var bCharExists = false;
|
||||
for (var b=0; b < arrPwdLen; b++) {
|
||||
if (arrPwd[a] == arrPwd[b] && a != b) { /* repeat character exists */
|
||||
bCharExists = true;
|
||||
/*
|
||||
Calculate icrement deduction based on proximity to identical characters
|
||||
Deduction is incremented each time a new match is discovered
|
||||
Deduction amount is based on total password length divided by the
|
||||
difference of distance between currently selected match
|
||||
*/
|
||||
nRepInc += Math.abs(arrPwdLen/(b-a));
|
||||
}
|
||||
}
|
||||
if (bCharExists) {
|
||||
nRepChar++;
|
||||
nUnqChar = arrPwdLen-nRepChar;
|
||||
nRepInc = (nUnqChar) ? Math.ceil(nRepInc/nUnqChar) : Math.ceil(nRepInc);
|
||||
}
|
||||
}
|
||||
|
||||
/* Check for sequential alpha string patterns (forward and reverse) */
|
||||
for (var s=0; s < 23; s++) {
|
||||
var sFwd = sAlphas.substring(s,parseInt(s+3));
|
||||
var sRev = sFwd.strReverse();
|
||||
if (pwd.toLowerCase().indexOf(sFwd) != -1 || pwd.toLowerCase().indexOf(sRev) != -1) { nSeqAlpha++; nSeqChar++;}
|
||||
}
|
||||
|
||||
/* Check for sequential numeric string patterns (forward and reverse) */
|
||||
for (var s=0; s < 8; s++) {
|
||||
var sFwd = sNumerics.substring(s,parseInt(s+3));
|
||||
var sRev = sFwd.strReverse();
|
||||
if (pwd.toLowerCase().indexOf(sFwd) != -1 || pwd.toLowerCase().indexOf(sRev) != -1) { nSeqNumber++; nSeqChar++;}
|
||||
}
|
||||
|
||||
/* Check for sequential symbol string patterns (forward and reverse) */
|
||||
for (var s=0; s < 8; s++) {
|
||||
var sFwd = sSymbols.substring(s,parseInt(s+3));
|
||||
var sRev = sFwd.strReverse();
|
||||
if (pwd.toLowerCase().indexOf(sFwd) != -1 || pwd.toLowerCase().indexOf(sRev) != -1) { nSeqSymbol++; nSeqChar++;}
|
||||
}
|
||||
|
||||
/* Modify overall score value based on usage vs requirements */
|
||||
|
||||
/* General point assignment */
|
||||
// $("nLengthBonus").innerHTML = "+ " + nScore;
|
||||
if (nAlphaUC > 0 && nAlphaUC < nLength) {
|
||||
nScore = parseInt(nScore + ((nLength - nAlphaUC) * 2));
|
||||
sAlphaUC = "+ " + parseInt((nLength - nAlphaUC) * 2);
|
||||
}
|
||||
if (nAlphaLC > 0 && nAlphaLC < nLength) {
|
||||
nScore = parseInt(nScore + ((nLength - nAlphaLC) * 2));
|
||||
sAlphaLC = "+ " + parseInt((nLength - nAlphaLC) * 2);
|
||||
}
|
||||
if (nNumber > 0 && nNumber < nLength) {
|
||||
nScore = parseInt(nScore + (nNumber * nMultNumber));
|
||||
sNumber = "+ " + parseInt(nNumber * nMultNumber);
|
||||
}
|
||||
if (nSymbol > 0) {
|
||||
nScore = parseInt(nScore + (nSymbol * nMultSymbol));
|
||||
sSymbol = "+ " + parseInt(nSymbol * nMultSymbol);
|
||||
}
|
||||
if (nMidChar > 0) {
|
||||
nScore = parseInt(nScore + (nMidChar * nMultMidChar));
|
||||
sMidChar = "+ " + parseInt(nMidChar * nMultMidChar);
|
||||
}
|
||||
// $("nAlphaUCBonus").innerHTML = sAlphaUC;
|
||||
// $("nAlphaLCBonus").innerHTML = sAlphaLC;
|
||||
// $("nNumberBonus").innerHTML = sNumber;
|
||||
// $("nSymbolBonus").innerHTML = sSymbol;
|
||||
// $("nMidCharBonus").innerHTML = sMidChar;
|
||||
|
||||
/* Point deductions for poor practices */
|
||||
if ((nAlphaLC > 0 || nAlphaUC > 0) && nSymbol === 0 && nNumber === 0) { // Only Letters
|
||||
nScore = parseInt(nScore - nLength);
|
||||
nAlphasOnly = nLength;
|
||||
sAlphasOnly = "- " + nLength;
|
||||
}
|
||||
if (nAlphaLC === 0 && nAlphaUC === 0 && nSymbol === 0 && nNumber > 0) { // Only Numbers
|
||||
nScore = parseInt(nScore - nLength);
|
||||
nNumbersOnly = nLength;
|
||||
sNumbersOnly = "- " + nLength;
|
||||
}
|
||||
if (nRepChar > 0) { // Same character exists more than once
|
||||
nScore = parseInt(nScore - nRepInc);
|
||||
sRepChar = "- " + nRepInc;
|
||||
}
|
||||
if (nConsecAlphaUC > 0) { // Consecutive Uppercase Letters exist
|
||||
nScore = parseInt(nScore - (nConsecAlphaUC * nMultConsecAlphaUC));
|
||||
sConsecAlphaUC = "- " + parseInt(nConsecAlphaUC * nMultConsecAlphaUC);
|
||||
}
|
||||
if (nConsecAlphaLC > 0) { // Consecutive Lowercase Letters exist
|
||||
nScore = parseInt(nScore - (nConsecAlphaLC * nMultConsecAlphaLC));
|
||||
sConsecAlphaLC = "- " + parseInt(nConsecAlphaLC * nMultConsecAlphaLC);
|
||||
}
|
||||
if (nConsecNumber > 0) { // Consecutive Numbers exist
|
||||
nScore = parseInt(nScore - (nConsecNumber * nMultConsecNumber));
|
||||
sConsecNumber = "- " + parseInt(nConsecNumber * nMultConsecNumber);
|
||||
}
|
||||
if (nSeqAlpha > 0) { // Sequential alpha strings exist (3 characters or more)
|
||||
nScore = parseInt(nScore - (nSeqAlpha * nMultSeqAlpha));
|
||||
sSeqAlpha = "- " + parseInt(nSeqAlpha * nMultSeqAlpha);
|
||||
}
|
||||
if (nSeqNumber > 0) { // Sequential numeric strings exist (3 characters or more)
|
||||
nScore = parseInt(nScore - (nSeqNumber * nMultSeqNumber));
|
||||
sSeqNumber = "- " + parseInt(nSeqNumber * nMultSeqNumber);
|
||||
}
|
||||
if (nSeqSymbol > 0) { // Sequential symbol strings exist (3 characters or more)
|
||||
nScore = parseInt(nScore - (nSeqSymbol * nMultSeqSymbol));
|
||||
sSeqSymbol = "- " + parseInt(nSeqSymbol * nMultSeqSymbol);
|
||||
}
|
||||
// $("nAlphasOnlyBonus").innerHTML = sAlphasOnly;
|
||||
// $("nNumbersOnlyBonus").innerHTML = sNumbersOnly;
|
||||
// $("nRepCharBonus").innerHTML = sRepChar;
|
||||
// $("nConsecAlphaUCBonus").innerHTML = sConsecAlphaUC;
|
||||
// $("nConsecAlphaLCBonus").innerHTML = sConsecAlphaLC;
|
||||
// $("nConsecNumberBonus").innerHTML = sConsecNumber;
|
||||
// $("nSeqAlphaBonus").innerHTML = sSeqAlpha;
|
||||
// $("nSeqNumberBonus").innerHTML = sSeqNumber;
|
||||
// $("nSeqSymbolBonus").innerHTML = sSeqSymbol;
|
||||
|
||||
/* Determine if mandatory requirements have been met and set image indicators accordingly */
|
||||
var arrChars = [nLength,nAlphaUC,nAlphaLC,nNumber,nSymbol];
|
||||
var arrCharsIds = ["nLength","nAlphaUC","nAlphaLC","nNumber","nSymbol"];
|
||||
var arrCharsLen = arrChars.length;
|
||||
// for (var c=0; c < arrCharsLen; c++) {
|
||||
// var oImg = $('div_' + arrCharsIds[c]);
|
||||
// var oBonus = $(arrCharsIds[c] + 'Bonus');
|
||||
// $(arrCharsIds[c]).innerHTML = arrChars[c];
|
||||
// if (arrCharsIds[c] == "nLength") { var minVal = parseInt(nMinPwdLen - 1); } else { var minVal = 0; }
|
||||
// if (arrChars[c] == parseInt(minVal + 1)) { nReqChar++; oImg.className = "pass"; oBonus.parentNode.className = "pass"; }
|
||||
// else if (arrChars[c] > parseInt(minVal + 1)) { nReqChar++; oImg.className = "exceed"; oBonus.parentNode.className = "exceed"; }
|
||||
// else { oImg.className = "fail"; oBonus.parentNode.className = "fail"; }
|
||||
// }
|
||||
nRequirements = nReqChar;
|
||||
if (pwd.length >= nMinPwdLen) { var nMinReqChars = 3; } else { var nMinReqChars = 4; }
|
||||
if (nRequirements > nMinReqChars) { // One or more required characters exist
|
||||
nScore = parseInt(nScore + (nRequirements * 2));
|
||||
sRequirements = "+ " + parseInt(nRequirements * 2);
|
||||
}
|
||||
// $("nRequirementsBonus").innerHTML = sRequirements;
|
||||
|
||||
/* Determine if additional bonuses need to be applied and set image indicators accordingly */
|
||||
var arrChars = [nMidChar,nRequirements];
|
||||
var arrCharsIds = ["nMidChar","nRequirements"];
|
||||
var arrCharsLen = arrChars.length;
|
||||
// for (var c=0; c < arrCharsLen; c++) {
|
||||
// var oImg = $('div_' + arrCharsIds[c]);
|
||||
// var oBonus = $(arrCharsIds[c] + 'Bonus');
|
||||
// $(arrCharsIds[c]).innerHTML = arrChars[c];
|
||||
// if (arrCharsIds[c] == "nRequirements") { var minVal = nMinReqChars; } else { var minVal = 0; }
|
||||
// if (arrChars[c] == parseInt(minVal + 1)) { oImg.className = "pass"; oBonus.parentNode.className = "pass"; }
|
||||
// else if (arrChars[c] > parseInt(minVal + 1)) { oImg.className = "exceed"; oBonus.parentNode.className = "exceed"; }
|
||||
// else { oImg.className = "fail"; oBonus.parentNode.className = "fail"; }
|
||||
// }
|
||||
|
||||
/* Determine if suggested requirements have been met and set image indicators accordingly */
|
||||
var arrChars = [nAlphasOnly,nNumbersOnly,nRepChar,nConsecAlphaUC,nConsecAlphaLC,nConsecNumber,nSeqAlpha,nSeqNumber,nSeqSymbol];
|
||||
var arrCharsIds = ["nAlphasOnly","nNumbersOnly","nRepChar","nConsecAlphaUC","nConsecAlphaLC","nConsecNumber","nSeqAlpha","nSeqNumber","nSeqSymbol"];
|
||||
var arrCharsLen = arrChars.length;
|
||||
// for (var c=0; c < arrCharsLen; c++) {
|
||||
// var oImg = $('div_' + arrCharsIds[c]);
|
||||
// var oBonus = $(arrCharsIds[c] + 'Bonus');
|
||||
// $(arrCharsIds[c]).innerHTML = arrChars[c];
|
||||
// if (arrChars[c] > 0) { oImg.className = "warn"; oBonus.parentNode.className = "warn"; }
|
||||
// else { oImg.className = "pass"; oBonus.parentNode.className = "pass"; }
|
||||
// }
|
||||
|
||||
/* Determine complexity based on overall score */
|
||||
if (nScore > 100) { nScore = 100; } else if (nScore < 0) { nScore = 0; }
|
||||
if (nScore >= 0 && nScore < 20) { sComplexity = "Very Weak"; }
|
||||
else if (nScore >= 20 && nScore < 40) { sComplexity = "Weak"; }
|
||||
else if (nScore >= 40 && nScore < 60) { sComplexity = "Good"; }
|
||||
else if (nScore >= 60 && nScore < 80) { sComplexity = "Strong"; }
|
||||
else if (nScore >= 80 && nScore <= 100) { sComplexity = "Very Strong"; }
|
||||
|
||||
/* Display updated score criteria to client */
|
||||
oScorebar.style.backgroundPosition = "-" + parseInt(nScore * 4) + "px 0px";
|
||||
oScore.innerHTML = nScore + "%";
|
||||
// oComplexity.innerHTML = sComplexity;
|
||||
}
|
||||
else {
|
||||
/* Display default score criteria to client */
|
||||
initPwdChk();
|
||||
oScore.innerHTML = nScore + "%";
|
||||
// oComplexity.innerHTML = sComplexity;
|
||||
}
|
||||
}
|
||||
|
||||
function togPwdMask() {
|
||||
var oPwd = $("passwordPwd");
|
||||
var oTxt = $("passwordTxt");
|
||||
var oMask = $("mask");
|
||||
if (oMask.checked) {
|
||||
oPwd.value = oTxt.value;
|
||||
oPwd.className = "";
|
||||
oTxt.className = "hide";
|
||||
}
|
||||
else {
|
||||
oTxt.value = oPwd.value;
|
||||
oPwd.className = "hide";
|
||||
oTxt.className = "";
|
||||
}
|
||||
}
|
||||
|
||||
function initPwdChk(restart) {
|
||||
/* Reset all form values to their default */
|
||||
var arrZeros = ["nLength","nAlphaUC","nAlphaLC","nNumber","nSymbol","nMidChar","nRequirements","nAlphasOnly","nNumbersOnly","nRepChar","nConsecAlphaUC","nConsecAlphaLC","nConsecNumber","nSeqAlpha","nSeqNumber","nSeqSymbol","nLengthBonus","nAlphaUCBonus","nAlphaLCBonus","nNumberBonus","nSymbolBonus","nMidCharBonus","nRequirementsBonus","nAlphasOnlyBonus","nNumbersOnlyBonus","nRepCharBonus","nConsecAlphaUCBonus","nConsecAlphaLCBonus","nConsecNumberBonus","nSeqAlphaBonus","nSeqNumberBonus","nSeqSymbolBonus"];
|
||||
var arrPassPars = ["nAlphasOnlyBonus","nNumbersOnlyBonus","nRepCharBonus","nConsecAlphaUCBonus","nConsecAlphaLCBonus","nConsecNumberBonus","nSeqAlphaBonus","nSeqNumberBonus","nSeqSymbolBonus"];
|
||||
var arrPassDivs = ["div_nAlphasOnly","div_nNumbersOnly","div_nRepChar","div_nConsecAlphaUC","div_nConsecAlphaLC","div_nConsecNumber","div_nSeqAlpha","div_nSeqNumber","div_nSeqSymbol"];
|
||||
var arrFailPars = ["nLengthBonus","nAlphaUCBonus","nAlphaLCBonus","nNumberBonus","nSymbolBonus","nMidCharBonus","nRequirementsBonus"];
|
||||
var arrFailDivs = ["div_nLength","div_nAlphaUC","div_nAlphaLC","div_nNumber","div_nSymbol","div_nMidChar","div_nRequirements"];
|
||||
// for (var i in arrZeros) { $(arrZeros[i]).innerHTML = "0"; }
|
||||
// for (var i in arrPassPars) { $(arrPassPars[i]).parentNode.className = "pass"; }
|
||||
// for (var i in arrPassDivs) { $(arrPassDivs[i]).className = "pass"; }
|
||||
// for (var i in arrFailPars) { $(arrFailPars[i]).parentNode.className = "fail"; }
|
||||
// for (var i in arrFailDivs) { $(arrFailDivs[i]).className = "fail"; }
|
||||
// $("passwordPwd").value = "";
|
||||
// $("passwordTxt").value = "";
|
||||
$("scorebar").style.backgroundPosition = "0 0";
|
||||
if (restart) {
|
||||
$("passwordPwd").className = "";
|
||||
$("passwordTxt").className = "hide";
|
||||
$("mask").checked = true;
|
||||
}
|
||||
}
|
||||
|
||||
addLoadEvent(function() { initPwdChk(1); });
|
||||
|
Reference in New Issue
Block a user