Android Question B4XFloatTextField password suggestions.

Hi, I am using B4XFloatTextField for password. However, the password I key into the field seems to turn up in suggestions. This reveals the user's passwords and even worse, the passwords would be stored in the keyboard dictionary. I don't face this problem with Android native TextViews, so how do I exactly solve this problem?

I have searched around in the forums and have come across this fix:
Suggested Fix for Disabling Suggestions (in B4X):
textField.InputType = Bit.Or(textField.InputType, 524288)

'Or

textField.InputType = Bit.Or(textField.InputType, 0x80000)

Neither of them worked for me. This is my code excerpt:

My Code in a Custom View (in B4X):
Private Sub Init
    Dim txtBox As EditText
    txtBox = txt_TextBox.TextField
    txtBox.Padding = Array As Int(0dip, 0dip, 0dip, 0dip)
    If getPasswordMode Then
        txtBox.InputType = Bit.Or(txtBox.InputType, 0x80000)
    End If
End Sub

This is what happens in the app:
IMG_20200521_014345.jpg
 
For reference, here are the properties for my password field:
b4afloattextfieldpasswordprops.png


Also, I find that the suggestions feature goes away automatically if I press the "Password Reveal" button twice, toggling it to plaintext and back. So a fix for me might be to upon init, auto toggle to plaintext and back. If there is a way to do it programmatically, it would be awesome. I don't mind if it is a method I have to keep calling whenever I initialize this field.
 
Last edited:
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Hi, I am using B4XFloatTextField for password. However, the password I key into the field seems to turn up in suggestions. This reveals the user's passwords and even worse, the passwords would be stored in the keyboard dictionary. I don't face this problem with Android native TextViews, so how do I exactly solve this problem?

I have searched around in the forums and have come across this fix:
Suggested Fix for Disabling Suggestions (in B4X):
textField.InputType = Bit.Or(textField.InputType, 524288)

'Or

textField.InputType = Bit.Or(textField.InputType, 0x80000)

Neither of them worked for me. This is my code excerpt:

My Code in a Custom View (in B4X):
Private Sub Init
    Dim txtBox As EditText
    txtBox = txt_TextBox.TextField
    txtBox.Padding = Array As Int(0dip, 0dip, 0dip, 0dip)
    If getPasswordMode Then
        txtBox.InputType = Bit.Or(txtBox.InputType, 0x80000)
    End If
End Sub

This is what happens in the app:
View attachment 94438
Try:

B4X:
txtBox.InputType = 131217

RBS
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The input type is now set to: TYPE_TEXT_FLAG_NO_SUGGESTIONS | TYPE_TEXT_VARIATION_PASSWORD
It should hide suggestions and it does hide when I test it here. Eventually it is up to the keyboard app to respect these flags.

You can try other input types (https://developer.android.com/reference/android/text/InputType) like this:
B4X:
Dim et as EditText = B4XField.TextField
et.InputType = ...
 
Upvote 0
Thank you so much Erel and RBS. Especially with the your latest post, Erel, I figured out why the suggestions kept coming up. It's my fault.

I was trying to make a Custom View that also has a Password Mode. A side effect of this intention is that I introduced an InputType property that is accessed and modified like this:
B4X:
Public Sub getInputType As Int
    Dim txtBox As EditText
    txtBox = txt_TextBox.TextField
    Return txtBox.InputType
End Sub

Public Sub setInputType(aInputType As Int)
    mProps.Put("InputType", GetStringFromInputType(aInputType))
    Dim txtBox As EditText
    txtBox = txt_TextBox.TextField
    txtBox.InputType = aInputType
End Sub

As there is no password type in the INPUT_TYPE constants within the EditText class, the custom InputType designer property actually undoes the TYPE_TEXT_VARIATION_PASSWORD input type that's implicitly set by the B4AFloatTextField that I have wrapped within. This is how I handle the designer property:
B4X:
Private Sub Redraw
    '...
    setInputType(GetInputTypeFromString(mProps.Get("InputType")))
    '...
End Sub

'...

Private Sub GetInputTypeFromString(inputTypeString As String) As Int
    Dim txtBox As EditText
    txtBox = txt_TextBox.TextField
    Select inputTypeString
        Case "NUMBERS"
            Return txtBox.INPUT_TYPE_NUMBERS
        Case "DECIMAL_NUMBERS"
            Return txtBox.INPUT_TYPE_DECIMAL_NUMBERS
        Case "TEXT"
            Return txtBox.INPUT_TYPE_TEXT
        Case "PHONE"
            Return txtBox.INPUT_TYPE_PHONE
        Case Else
            Return txtBox.INPUT_TYPE_NONE
    End Select
End Sub

To fix this, I have created a new sub to add the password aspect to the InputType setting using hardcoded hexadecimal values:
B4X:
Private Sub AddPasswordToInputType(inputType As Int) As Int
    Dim txtBox As EditText
    txtBox = txt_TextBox.TextField
    Select inputType
        Case txtBox.INPUT_TYPE_NUMBERS
            Return Bit.Or(0x10, 0x80000) 'TYPE_NUMBER_VARIATION_PASSWORD | TYPE_TEXT_FLAG_NO_SUGGESTIONS
        Case txtBox.INPUT_TYPE_TEXT
            Return Bit.Or(0x80, 0x80000) 'TYPE_TEXT_VARIATION_PASSWORD | TYPE_TEXT_FLAG_NO_SUGGESTIONS
        Case Else
            Return inputType
    End Select
End Sub

And finally, I modified setInputType to use this method:
B4X:
Public Sub setInputType(aInputType As Int)
    mProps.Put("InputType", GetStringFromInputType(aInputType))
    Dim finalInputType As Int
    If getPasswordMode Then
        finalInputType = AddPasswordToInputType(aInputType)
    Else
        finalInputType = aInputType
    End If
    Dim txtBox As EditText
    txtBox = txt_TextBox.TextField
    txtBox.InputType = finalInputType
End Sub

Thank you Erel, again, and I am deeply sorry for the false alarm I have caused in this thread. I hope this clarifies things for anyone who might have made the same mistake as I did.
 
Last edited:
Upvote 0
Top