From ad9ca125a09447470255eaa860e8eaa0908d2000 Mon Sep 17 00:00:00 2001 From: larena1 <60823161+larena1@users.noreply.github.com> Date: Fri, 10 Mar 2023 11:39:20 +0100 Subject: [PATCH] [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> --- src/Android/Autofill/FieldCollection.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Android/Autofill/FieldCollection.cs b/src/Android/Autofill/FieldCollection.cs index 8b29ab8e3..a01aaad70 100644 --- a/src/Android/Autofill/FieldCollection.cs +++ b/src/Android/Autofill/FieldCollection.cs @@ -102,7 +102,7 @@ namespace Bit.Droid.Autofill if (!_usernameFields.Any()) { - _usernameFields = Fields.Where(f => FieldHasUsernameTerms(f)).ToList(); + _usernameFields = Fields.Where(f => FieldIsUsername(f)).ToList(); } } return _usernameFields; @@ -327,13 +327,18 @@ namespace Bit.Droid.Autofill } return inputTypePassword && !ValueContainsAnyTerms(f.IdEntry, _ignoreSearchTerms) && - !ValueContainsAnyTerms(f.Hint, _ignoreSearchTerms) && !FieldHasUsernameTerms(f); + !ValueContainsAnyTerms(f.Hint, _ignoreSearchTerms) && !FieldIsUsername(f); } private bool FieldHasPasswordTerms(Field f) { 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) { @@ -350,4 +355,4 @@ namespace Bit.Droid.Autofill return terms.Any(t => lowerValue.Contains(t)); } } -} \ No newline at end of file +}