Give a chance to fields with type other than text and email to be a username (improve website compatibility)

This commit is contained in:
Grégory Soutadé 2015-11-05 18:16:33 +01:00
parent b255a8cd90
commit 075dd914f1
2 changed files with 104 additions and 48 deletions

View File

@ -265,6 +265,48 @@ function wildcard_domain(domain)
return ""; return "";
} }
function _add_name(logins, name)
{
for(var i=0; i<logins.length; i++)
if (logins[i] == name) return ;
logins.push(name);
}
function try_get_name(fields, type_filters, match)
{
var user = null;
var all_logins = new Array();
for (var i=0; i<fields.length; i++)
{
var field = fields[i];
for (var a=0; a<type_filters.length; a++)
{
if ((match && field.getAttribute("type") == type_filters[a]) ||
(!match && field.getAttribute("type") != type_filters[a]))
{
if (field.hasAttribute("name") && field.value != "")
{
name = field.getAttribute("name");
// Subset of common user field
if (name == "user") user = field.value;
else if (name == "usr") user = field.value;
else if (name == "username") user = field.value;
else if (name == "login") user = field.value;
_add_name(all_logins, field.value);
}
}
}
}
if (user != null)
return new Array(user);
else
return all_logins;
}
function on_sumbit(e) function on_sumbit(e)
{ {
var form = this; var form = this;
@ -279,32 +321,18 @@ function on_sumbit(e)
debug("salt " + salt); debug("salt " + salt);
var user = null; type_filters = new Array();
var all_logins = new Array();
// Get all <input type="text"> && <input type="email"> // Get all <input type="text"> && <input type="email">
for (var i=0; i<fields.length; i++) type_filters.push("text");
{ type_filters.push("email");
var field = fields[i]; logins = try_get_name(fields, type_filters, true);
if (field.getAttribute("type") == "text" || field.getAttribute("type") == "email")
{
if (field.hasAttribute("name") && field.value != "")
{
name = field.getAttribute("name");
// Subset of common user field
if (name == "user") user = field.value;
else if (name == "usr") user = field.value;
else if (name == "username") user = field.value;
else if (name == "login") user = field.value;
all_logins.push(field.value);
}
}
}
if (user != null) // Get all other fields except text, email and password
logins = new Array(user); if (!logins.length)
else {
logins = all_logins; type_filters.push("password");
logins = try_get_name(fields, type_filters, false);
}
// Look for <input type="password" value="@@..."> // Look for <input type="password" value="@@...">
for (var i=0; i<fields.length; i++) for (var i=0; i<fields.length; i++)

View File

@ -272,6 +272,48 @@ function wildcard_domain(domain)
return ""; return "";
} }
function _add_name(logins, name)
{
for(var i=0; i<logins.length; i++)
if (logins[i] == name) return ;
logins.push(name);
}
function try_get_name(fields, type_filters, match)
{
var user = null;
var all_logins = new Array();
for (var i=0; i<fields.length; i++)
{
var field = fields[i];
for (var a=0; a<type_filters.length; a++)
{
if ((match && field.getAttribute("type") == type_filters[a]) ||
(!match && field.getAttribute("type") != type_filters[a]))
{
if (field.hasAttribute("name") && field.value != "")
{
name = field.getAttribute("name");
// Subset of common user field
if (name == "user") user = field.value;
else if (name == "usr") user = field.value;
else if (name == "username") user = field.value;
else if (name == "login") user = field.value;
_add_name(all_logins, field.value);
}
}
}
}
if (user != null)
return new Array(user);
else
return all_logins;
}
function on_sumbit(e) function on_sumbit(e)
{ {
var form = this; var form = this;
@ -286,32 +328,18 @@ function on_sumbit(e)
debug("salt " + salt); debug("salt " + salt);
var user = null; type_filters = new Array();
var all_logins = new Array();
// Get all <input type="text"> && <input type="email"> // Get all <input type="text"> && <input type="email">
for (var i=0; i<fields.length; i++) type_filters.push("text");
{ type_filters.push("email");
var field = fields[i]; logins = try_get_name(fields, type_filters, true);
if (field.getAttribute("type") == "text" || field.getAttribute("type") == "email")
{
if (field.hasAttribute("name") && field.value != "")
{
name = field.getAttribute("name");
// Subset of common user field
if (name == "user") user = field.value;
else if (name == "usr") user = field.value;
else if (name == "username") user = field.value;
else if (name == "login") user = field.value;
all_logins.push(field.value);
}
}
}
if (user != null) // Get all other fields except text, email and password
logins = new Array(user); if (!logins.length)
else {
logins = all_logins; type_filters.push("password");
logins = try_get_name(fields, type_filters, false);
}
// Look for <input type="password" value="@@..."> // Look for <input type="password" value="@@...">
for (var i=0; i<fields.length; i++) for (var i=0; i<fields.length; i++)