x


GUILayout.PasswordField() shows whole password when running on iOS before changing characters!?!

When I test my game's twitter login view in the editor, the GUILayout.PasswordField() works as expected hiding every character immediately and revealing nothing. However when I run it on my iPhone 4 and it has to have the characters input from the iOS keyboard it behaves much differently. It actually shows the ENTIRE PASSWORD until the user hits the Done button confirming they are finished entering their password where it finally turns them all into the asterisk character I gave it. There's no way I can use it like this as it would potentially reveal many of my user's twitter passwords to onlookers. Any ideas on how to fix this would be INDESCRIBABLY HELPFUL! I'll add my OnGUI() implementation here.

static var twitterUser : String = "";
static var twitterPassword : String = "";

function OnGUI()
{
    if (rootView.highRes)
    {
        GUI.skin = rootView.highResGUISkin;
    }
    else
    {
        GUI.skin = rootView.lowResGUISkin;
    }
    if (selected) // this turns true when the root view calls one of this view's EnterFrom functions
    {
        startPos = Mathf.Lerp(startPos, endPos, Time.deltaTime * rootView.guiDamp);
        GUILayout.BeginArea(Rect(startPos, 0, Screen.width, Screen.height));
        GUILayout.BeginVertical();// begin open centering junk
        GUILayout.FlexibleSpace();
        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();// end open centering junk
        GUILayout.BeginVertical("box");
        GUILayout.Box("TWITTER ACCOUNT");
        GUILayout.BeginHorizontal();
        GUILayout.BeginVertical();
        GUILayout.Label("USERNAME", "twitterLabel");
        GUILayout.Label("PASSWORD", "twitterLabel");
        GUILayout.EndVertical();
        GUILayout.BeginVertical();
        twitterUser = GUILayout.TextField(twitterUser, 15);
        twitterPassword = GUILayout.PasswordField(twitterPassword, "*"[0]);
        GUILayout.EndVertical();
        GUILayout.EndHorizontal();
        GUILayout.EndVertical();
        GUILayout.FlexibleSpace();// begin close centering junk
        GUILayout.EndHorizontal();
        GUILayout.FlexibleSpace();
        GUILayout.EndVertical();// end close centering junk
        GUILayout.EndArea();
    }
}
more ▼

asked Mar 30 '11 at 07:43 PM

franktinsley gravatar image

franktinsley
73 6 7 12

Filed a bug report. Hopefully they can find a fix for me soon so I don't end up using a hack work around.

Apr 06 '11 at 02:33 PM franktinsley

Bug is confirmed and with a developer for fixing. (June 29th 2011)

Jun 29 '11 at 01:14 PM Graham Dunnett ♦♦
(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

Until the bug is fixed, you may be able to get around it by making the text invisible by changing the transparency, and then drawing a series of "*" over top in the regular color of it equal to the length of the text. e.g. (untested, but should give the gist)

public static string MyPasswordField( string password )
{
  Color oldColor = GUI.contentColor;                  // save it
  GUI.contentColor = new Color( 0,0,0,0 );            // transparent (0 alpha)
  password = GUILayout.TextField( password );         // regular field, invis text
  GUI.contentColor = oldColor;                        // restore color
  Rect r = GUILayoutUtility.GetLastRect();            // wherever that was, find out
  GUI.Label( r, new string( '*', password.Length ) ); // draw * over top
  return password;
}

If the GUI.contentColor doesn't work as expected you could just make a special "invisible text textfield" GUIStyle and pass that instead (same basic idea, just a different way).

more ▼

answered Jun 29 '11 at 06:05 PM

Molix gravatar image

Molix
4.8k 17 27 66

Just tested, it works flawlessy. Thanks a lot, I really needed this!

But unfortunately, the original bug is still here...

Apr 23 at 10:12 PM DanjelRicci
(comments are locked)
10|3000 characters needed characters left

Almost a year has passed and this bug is still there...

The problem with the previous hack from Molix is that the virtual keyboard is still showing the password on my iPad...

To get around that, you may use the hack from Molix and hide the keyboard text field:

TouchScreenKeyboard.hideInput=true;

Or you may hide the GUI text when typing the password on the virtual keyboard:

var oldColor : Color = GUI.contentColor;
if (TouchScreenKeyboard.visible) {
    GUI.contentColor = new Color(0,0,0,0);
}
password = GUILayout.PasswordField(password, "*"[0]);
if (TouchScreenKeyboard.visible) {
    GUI.contentColor = oldColor;
}

(This code is for Unity 3.5, replace TouchScreenKeyboard by iPhoneKeyboard if you are using Unity 3.4)

This last solution is not perfect since the password is still briefly displayed when the keyboard is sliding...

more ▼

answered Jan 27 '12 at 04:59 PM

bournifle gravatar image

bournifle
86

(comments are locked)
10|3000 characters needed characters left

I've found a workaround for this bug, using an invisible button and the TouchScreenKeyboard.Open() function.

See my post (the 4th one) for an example here: http://forum.unity3d.com/threads/65337-GUI.PasswordField-issue

more ▼

answered Feb 10 '12 at 11:44 AM

bournifle gravatar image

bournifle
86

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3811
x2026
x78
x23

asked: Mar 30 '11 at 07:43 PM

Seen: 1934 times

Last Updated: Apr 23 at 10:12 PM