Password TextField losing Text value?

Issue on: On macOS (64Bit) with Xojo 2018 R1.1
NO issue on: Windows 7 - 10, 32 and 64bit

UI:
A (Login) Window with a Name + Password TextField and 2 PictureButtons (Einhugur) and 4 Labels.

Workflow:
While the Window opens, a Thread connects to a mySQL Server and keeps the connection alive. Until the mySQL connection is established, the 2 TextFields and the 2 Buttons are Enable=False. Once the mySQL Connection is established, a timer Enables the TextFields and Buttons.
When the User hits an “EndKey” in the Password TextField or when the User clicks the LogIn Button of those 2 Buttons, the TextFields and Buttons are Enabled=False and the Login is verified with the mySQL Server.
This worked flawlessly since 5 years.

But suddenly Logging in on a Mac was no longer possible, because the Password was always wrong. After many many Breaks in the Debugger, i was able to reveal the following issue:

Nearly everytime, the String Value of the Password Field goes from a non empty String value to an empty String Value, the moment between i set the Enabled=False Property and the next Code Line (no matter what is next).

I haven’t been able to reproduce this in a simple project yet for a report. Has anyone else seen this behaviour before?

I can’t reproduce that here either. Is the TextChange event firing?

This is expected behavior: <https://xojo.com/issue/43321> - Text in password TextField disappears when disabled

No, it’s not.

Yes and no. The visual representation of the Text may/should disapear but when you reenable the Object again, the Text should also re-apear.

the strange thing is, the screen still shows that there is a Value in the Field (dots…) but the Text Property of the same Field is empty at the same time.

[quote=398839:@Sascha S]Yes and no. The visual representation of the Text may/should disapear but when you reenable the Object again, the Text should also re-apear.

the strange thing is, the screen still shows that there is a Value in the Field (dots…) but the Text Property of the same Field is empty at the same time.[/quote]
Nothing should re-populate or appear. That’s data security. It’s NSSecureTextField.

As I don’t understand what is going on, I did a test:

  • if the password field has the focus, when I disable the field the value is “lost” or return to previous value
  • if the password field doesn’t have the focus, then when disable it keep the correct value even after it is re-enabled

First I put 1 in both but disable when focus is on password, result password field nothing
Then I put 1 again, change the focus, result password field 1
Then I put 2 in both, focus on text, result password field 2
Then I put 3 in both, keep password on focus, disable, password value 2 (not 3 or nothing)

Well if any of this behavior seems wrong to you, in this instance you would have to file a report with Apple.

[quote=398846:@Alberto De Poo]if the password field has the focus, when I disable the field the value is “lost” or return to previous value
if the password field doesn’t have the focus, then when disable it keep the correct value even after it is re-enabled[/quote]

Thank you all! :slight_smile:

Alberto’s example shows perfectly what’s happening. The simple solution to my issue was to store the Hash of the Password.Text into a String Variable and then disable the Password Field for a Login attempt.

Kem, thank you for trying to reproduce it.
Tim, thank you for explaining why this makes sense. I agree with you.
And thank you Alberto for creating this example and the animation.

Thank you all! :slight_smile:

On a side note. I think it worked for so long because in the past i used a PushButton which was set to be the Default Button and catched the Focus when i hit the Enter Key. Recently i switched to Picture Buttons by Einhugur and i had to catch the “EndKey’s” in the TextChange Event of the Password Field. This lead to a focussed Password Field the moment i disable it for the Login attempt. :wink:

Do not misunderstand me please, it was my fault not anything wrong with Bjorns Picture Button (i LOVE 'em (those Button’s)) :smiley:

At least you found the root cause too!
I might recommend you set TextField.ReadOnly = true instead of disabling it.

A lot of things do not make sense to me (until they do), that’s why I test things until they make sense.

To me, the idea that the password field should disappear makes sense, but it is not happening here. My test show that only if the password field has focus and it is disabled, then the text content is reverted to the previous value.

I put 1 in there, without changing focus then it disappear because the previous value is nothing.
I put 2 there, changed focus then the value 2 stay.
I put 3 there, keep the focus, then value 2 is back again.

I would prefer that if the password value just disappear if the password text field is disabled, with or without focus.

So now I did more tests:

  • changed TextField2.Enabled = False to TextField2.ReadOnly = True
    result: the password value is not reverted to previous value
  • added TextField2.ReadOnly = True before TextField2.Enabled = False
    result: the password value is not reverted to previous value and the field is disabled
    both with or without focus.

So now I know that if the password field has focus and is not read only, it will revert back to previous value if the textfield is disabled. So to make it work as Sascha and Tim pointed out, is better to a) change the focus or, b) set the readonly value before disabling the field or c) get the hash value before disabling the field and maybe clear the value for security purposes.

I just saw a simple project in one of the feedback cases:

  • a TextField (password)
  • a label
  • a default PushButton
    in PushButton Action:

TextField1.Enabled = False Label1.Text = TextField1.Text

If you write something in TextField then click the PushButton (without using TAB or Enter in the TextField) the TextField and Label will clear.

If you change the code to:

Label1.Text = TextField1.Text TextField1.Enabled = False

And do the same, now the label will show what was typed in TextField, this make sense to me because that is done before the Enabled = False, but what I didn’t expect was that the TextField will not clear.

Then I did another test using the original code:

  • added TextChange to TextField1 with Label1.Text = me.Text

Now the label change as I type every letter, but then I press the PushButton and the TextField will not clear the contents. For me this is not consistent behavior. I expect either always delete TextField password contents when Enable = False or never do it.

It looks like the same thing happen even if TextField is not set to Password.

BTW, it’s to “lose”. “Loose” means not tight.

I added information to that case. I don’t think it is working as expected.

Fixed