From 2a44937d091046526dbc558f8c1eece7c3d1d300 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Sat, 17 Sep 2016 13:47:14 -0400 Subject: [PATCH] smarter username field selection for no form condition --- src/iOS.Extension/Models/FillScript.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/iOS.Extension/Models/FillScript.cs b/src/iOS.Extension/Models/FillScript.cs index 2ed4803cd..bc2ca595b 100644 --- a/src/iOS.Extension/Models/FillScript.cs +++ b/src/iOS.Extension/Models/FillScript.cs @@ -85,10 +85,20 @@ namespace Bit.iOS.Extension.Models } else if(passwordFields.Count() == 1) { + // The page does not have any forms with password fields. Use the one password field on the page and the + // input field just before it as the username. + password = passwordFields.First(); if(password.ElementNumber > 0) { - username = pageDetails.Fields[password.ElementNumber - 1]; + username = pageDetails.Fields.LastOrDefault(f => + (f.Type == "text" || f.Type == "email") + && f.ElementNumber < password.ElementNumber); + + if(username == null) + { + username = pageDetails.Fields[password.ElementNumber - 1]; + } } }