mirror of
https://github.com/bitwarden/android.git
synced 2025-01-12 11:17:30 +03:00
refactor ignoresearch and password terms detection
This commit is contained in:
parent
5103c80e1e
commit
da6e271584
1 changed files with 32 additions and 14 deletions
|
@ -11,6 +11,8 @@ namespace Bit.Android.Autofill
|
||||||
{
|
{
|
||||||
private List<Field> _passwordFields = null;
|
private List<Field> _passwordFields = null;
|
||||||
private List<Field> _usernameFields = null;
|
private List<Field> _usernameFields = null;
|
||||||
|
private HashSet<string> _ignoreSearchTerms = new HashSet<string> { "search", "find" };
|
||||||
|
private HashSet<string> _passwordTerms = new HashSet<string> { "password", "pswd" };
|
||||||
|
|
||||||
public HashSet<int> Ids { get; private set; } = new HashSet<int>();
|
public HashSet<int> Ids { get; private set; } = new HashSet<int>();
|
||||||
public List<AutofillId> AutofillIds { get; private set; } = new List<AutofillId>();
|
public List<AutofillId> AutofillIds { get; private set; } = new List<AutofillId>();
|
||||||
|
@ -58,21 +60,10 @@ namespace Bit.Android.Autofill
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_passwordFields = Fields
|
_passwordFields = Fields.Where(f => FieldIsPassword(f)).ToList();
|
||||||
.Where(f =>
|
|
||||||
(!f.IdEntry?.ToLowerInvariant().Contains("search") ?? true) &&
|
|
||||||
(!f.Hint?.ToLowerInvariant().Contains("search") ?? true) &&
|
|
||||||
(
|
|
||||||
f.InputType.HasFlag(InputTypes.TextVariationPassword) ||
|
|
||||||
f.InputType.HasFlag(InputTypes.TextVariationVisiblePassword) ||
|
|
||||||
f.InputType.HasFlag(InputTypes.TextVariationWebPassword)
|
|
||||||
)
|
|
||||||
).ToList();
|
|
||||||
if(!_passwordFields.Any())
|
if(!_passwordFields.Any())
|
||||||
{
|
{
|
||||||
_passwordFields = Fields.Where(f =>
|
_passwordFields = Fields.Where(f => FieldHasPasswordTerms(f)).ToList();
|
||||||
(f.IdEntry?.ToLowerInvariant().Contains("password") ?? false)
|
|
||||||
|| (f.Hint?.ToLowerInvariant().Contains("password") ?? false)).ToList();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,7 +96,8 @@ namespace Bit.Android.Autofill
|
||||||
{
|
{
|
||||||
foreach(var passwordField in PasswordFields)
|
foreach(var passwordField in PasswordFields)
|
||||||
{
|
{
|
||||||
var usernameField = Fields.TakeWhile(f => f.AutofillId != passwordField.AutofillId).LastOrDefault();
|
var usernameField = Fields.TakeWhile(f => f.AutofillId != passwordField.AutofillId)
|
||||||
|
.LastOrDefault();
|
||||||
if(usernameField != null)
|
if(usernameField != null)
|
||||||
{
|
{
|
||||||
_usernameFields.Add(usernameField);
|
_usernameFields.Add(usernameField);
|
||||||
|
@ -312,5 +304,31 @@ namespace Bit.Android.Autofill
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool FieldIsPassword(Field f)
|
||||||
|
{
|
||||||
|
var inputTypePassword = f.InputType.HasFlag(InputTypes.TextVariationPassword) ||
|
||||||
|
f.InputType.HasFlag(InputTypes.TextVariationVisiblePassword) ||
|
||||||
|
f.InputType.HasFlag(InputTypes.TextVariationWebPassword);
|
||||||
|
|
||||||
|
return inputTypePassword && !ValueContainsAnyTerms(f.IdEntry, _ignoreSearchTerms) &&
|
||||||
|
!ValueContainsAnyTerms(f.Hint, _ignoreSearchTerms);
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool FieldHasPasswordTerms(Field f)
|
||||||
|
{
|
||||||
|
return ValueContainsAnyTerms(f.IdEntry, _passwordTerms) || ValueContainsAnyTerms(f.Hint, _passwordTerms);
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool ValueContainsAnyTerms(string value, HashSet<string> terms)
|
||||||
|
{
|
||||||
|
if(string.IsNullOrWhiteSpace(value))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var lowerValue = value.ToLowerInvariant();
|
||||||
|
return terms.Any(t => lowerValue.Contains(t));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue