Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between android:inputType="textPassword", "textVisiblePassword","textWebPassword" and "numberPassword" in android?

Can anyone explain the differences between the

   android:inputType="textPassword",    android:inputType="textVisiblePassword",    android:inputType="textWebPassword",    android:inputType="numberPassword" 

of EditText ViewGroup in Android Layout?

like image 458
kablu Avatar asked May 04 '14 08:05

kablu


1 Answers

Even though it has been already answered I'll add some more details to the differences in password InputType variations:

  1. android:inputType="textPassword": Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_PASSWORD i.e. it allows you to enter a string that is taken as a password (hidden and preventing autocompletion and suggestions unless set explicitly). This one is mostly used when we want to enter passwords.
  2. android:inputType="textVisiblePassword": Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_VISIBLE_PASSWORD and is the same as the previous one but the password is visible (useful if you want to use it to allow to see the password as default because it prevents the autocompletion and suggestions unless they are set explicitly - it is advisable to also have a way to hide the password)
  3. android:inputType="numberPassword": Corresponds to TYPE_CLASS_NUMBER | TYPE_NUMBER_VARIATION_PASSWORD same as android:inputType="textPassword" but you can only enter numbers. Take into account that if you use it the password will not be so strong, so I wouldn't recommend using it when dealing with sensitive data unless it is used along with another type of user authentication.
  4. android:inputType="textWebPassword": Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_WEB_PASSWORD and has the same behaviour as android:inputType="textPassword" but it is intended to be used in a web form i.e. inside a browser page (any web form control that takes input from a user). So this shall not be used in an EditText native control. An example of using this would be to disable AutoSuggestion from Android in a WebView by wrapping a WebView and changing EditorInfo input type to add the flag InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD inside the onCreateInputConnectionmethod.

As an example of the last one taken from the link:

public class NoSuggestionsWebView extends WebView {     ...      @Override     public InputConnection onCreateInputConnection(EditorInfo outAttrs)     {         InputConnection ic = super.onCreateInputConnection(outAttrs);          outAttrs.inputType &= ~EditorInfo.TYPE_MASK_VARIATION; /* clear VARIATION type to be able to set new value */         outAttrs.inputType |= InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD; /* WEB_PASSWORD type will prevent form suggestions */          return ic;     } } 

I hope it is clear now the differences and mainly between android:inputType="textPassword" and android:inputType="textWebPassword"

like image 68
fmaccaroni Avatar answered Oct 08 '22 22:10

fmaccaroni