Autofill: fill emailAddress fields with username
This commit is contained in:
@@ -55,13 +55,15 @@ namespace keepass2android.services.Kp2aAutofill
|
||||
|
||||
foreach (string key in pwEntryOutput.OutputStrings.GetKeys())
|
||||
{
|
||||
|
||||
FilledAutofillField field =
|
||||
new FilledAutofillField
|
||||
{
|
||||
AutofillHints = new[] {GetCanonicalHintFromKp2aField(key)},
|
||||
AutofillHints = GetCanonicalHintsFromKp2aField(key).ToArray(),
|
||||
TextValue = pwEntryOutput.OutputStrings.ReadSafe(key)
|
||||
};
|
||||
fieldCollection.Add(field);
|
||||
|
||||
}
|
||||
if (IsCreditCard(pwEntry, context) && pwEntry.Expires)
|
||||
{
|
||||
@@ -112,42 +114,47 @@ namespace keepass2android.services.Kp2aAutofill
|
||||
|| pwEntry.Strings.Exists(context.GetString(Resource.String.TemplateField_CreditCard_CVV));
|
||||
}
|
||||
|
||||
private static readonly Dictionary<string, string> keyToHint = BuildKeyToHint();
|
||||
private static readonly Dictionary<string, List<string>> keyToHint = BuildKeyToHints();
|
||||
|
||||
public static string GetKp2aKeyFromHint(string canonicalHint)
|
||||
{
|
||||
var key = keyToHint.FirstOrDefault(p => p.Value.Equals(canonicalHint, StringComparison.OrdinalIgnoreCase)).Key;
|
||||
var key = keyToHint.FirstOrDefault(p => p.Value.Contains(canonicalHint)).Key;
|
||||
if (string.IsNullOrWhiteSpace(key))
|
||||
return canonicalHint;
|
||||
return key;
|
||||
}
|
||||
|
||||
private static Dictionary<string, string> BuildKeyToHint()
|
||||
private static Dictionary<string, List<string>> BuildKeyToHints()
|
||||
{
|
||||
var result = new Dictionary<string, string>
|
||||
var result = new Dictionary<string, List<string>>
|
||||
{
|
||||
{PwDefs.UserNameField, View.AutofillHintUsername},
|
||||
{PwDefs.PasswordField, View.AutofillHintPassword},
|
||||
{PwDefs.UrlField, W3cHints.URL},
|
||||
{PwDefs.UserNameField, new List<string>{View.AutofillHintUsername, View.AutofillHintEmailAddress}},
|
||||
{PwDefs.PasswordField, new List<string>{View.AutofillHintPassword}},
|
||||
{PwDefs.UrlField, new List<string>{W3cHints.URL}},
|
||||
{
|
||||
Application.Context.GetString(Resource.String.TemplateField_CreditCard_CVV),
|
||||
View.AutofillHintCreditCardSecurityCode
|
||||
new List<string>{View.AutofillHintCreditCardSecurityCode}
|
||||
},
|
||||
{
|
||||
Application.Context.GetString(Resource.String.TemplateField_CreditCard_Owner),
|
||||
W3cHints.CC_NAME
|
||||
new List<string>{W3cHints.CC_NAME}
|
||||
},
|
||||
{Application.Context.GetString(Resource.String.TemplateField_Number), View.AutofillHintCreditCardNumber},
|
||||
{Application.Context.GetString(Resource.String.TemplateField_IdCard_Name), View.AutofillHintName},
|
||||
{Application.Context.GetString(Resource.String.TemplateField_Number), new List<string>{View.AutofillHintCreditCardNumber}},
|
||||
{Application.Context.GetString(Resource.String.TemplateField_IdCard_Name), new List<string>{View.AutofillHintName}},
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
private static string GetCanonicalHintFromKp2aField(string key)
|
||||
private static List<string> GetCanonicalHintsFromKp2aField(string key)
|
||||
{
|
||||
if (!keyToHint.TryGetValue(key, out string result))
|
||||
result = key;
|
||||
result = result.ToLower();
|
||||
List<string> result = new List<string>() {key};
|
||||
List<string> hints;
|
||||
if (keyToHint.TryGetValue(key, out hints))
|
||||
result = hints;
|
||||
for (int i = 0; i < result.Count; i++)
|
||||
{
|
||||
result[i] = result[i].ToLower();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user