[PS-2486] Finally stop filling password into username field (#2367)

* Finally stop filling password into username field

The logic in #2331 is unfortunately not very reliable as it'll only detect fields that have one of "email", "phone" or "username" in their id as username fields.
This commit ensures that additonally fields that have TextVariationWebEmailAddress are also detected as username fields.

* Add TextVariationEmailAddress

* Remove

---------

Co-authored-by: aj-rosado <109146700+aj-rosado@users.noreply.github.com>
This commit is contained in:
larena1 2023-03-10 11:39:20 +01:00 committed by GitHub
parent fe12b0e908
commit ad9ca125a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -102,7 +102,7 @@ namespace Bit.Droid.Autofill
if (!_usernameFields.Any()) if (!_usernameFields.Any())
{ {
_usernameFields = Fields.Where(f => FieldHasUsernameTerms(f)).ToList(); _usernameFields = Fields.Where(f => FieldIsUsername(f)).ToList();
} }
} }
return _usernameFields; return _usernameFields;
@ -327,7 +327,7 @@ namespace Bit.Droid.Autofill
} }
return inputTypePassword && !ValueContainsAnyTerms(f.IdEntry, _ignoreSearchTerms) && return inputTypePassword && !ValueContainsAnyTerms(f.IdEntry, _ignoreSearchTerms) &&
!ValueContainsAnyTerms(f.Hint, _ignoreSearchTerms) && !FieldHasUsernameTerms(f); !ValueContainsAnyTerms(f.Hint, _ignoreSearchTerms) && !FieldIsUsername(f);
} }
private bool FieldHasPasswordTerms(Field f) private bool FieldHasPasswordTerms(Field f)
@ -335,6 +335,11 @@ namespace Bit.Droid.Autofill
return ValueContainsAnyTerms(f.IdEntry, _passwordTerms) || ValueContainsAnyTerms(f.Hint, _passwordTerms); return ValueContainsAnyTerms(f.IdEntry, _passwordTerms) || ValueContainsAnyTerms(f.Hint, _passwordTerms);
} }
private bool FieldIsUsername(Field f)
{
return f.InputType.HasFlag(InputTypes.TextVariationWebEmailAddress) || FieldHasUsernameTerms(f);
}
private bool FieldHasUsernameTerms(Field f) private bool FieldHasUsernameTerms(Field f)
{ {
return ValueContainsAnyTerms(f.IdEntry, _usernameTerms) || ValueContainsAnyTerms(f.Hint, _usernameTerms); return ValueContainsAnyTerms(f.IdEntry, _usernameTerms) || ValueContainsAnyTerms(f.Hint, _usernameTerms);