Sign in to follow this  
Followers 0
chamach

Password Char...

11 posts in this topic

Hello all of you,

This code does not seems to work in the current beta of AutoIt3 : the Edit control shows clearly what I am typing instead of a string of "*".

$ES_PASSWORD = "0x0020"

GUICreate ("Pass")
GUISetControl ("Edit", "", 10, 10, 50, 20, $ES_PASSWORD)
GUIWaitClose ()
GuiDelete ()

Am I doing something wrong ? :D

Thanks a lot !


Cervélo Soloist 2004 & Cervélo P3C 2007

Share this post


Link to post
Share on other sites



Oooops... :huh2:

If works perfectly with :

$ES_PASSWORD = "0x0020"

GUICreate ("Pass")
GUISetControl ("input", "", 10, 10, 50, 20, $ES_PASSWORD)
GUIWaitClose ()
GuiDelete ()

Sorry !

But I am finally happy... :D


Cervélo Soloist 2004 & Cervélo P3C 2007

Share this post


Link to post
Share on other sites

Oooops...  :)

If works perfectly with :

$ES_PASSWORD = "0x0020"

GUICreate ("Pass")
GUISetControl ("input", "", 10, 10, 50, 20, $ES_PASSWORD)
GUIWaitClose ()
GuiDelete ()

Sorry !

But I am finally happy...  :huh2:

You get it ES_PASSWORD is for "input" control not for "edit".

:D

Share this post


Link to post
Share on other sites

Hi,

I'm not certain this is the right place to ask, but it seems related. Once I have an input box set with $ES_PASSWORD to hide input, I want to use a checkbox that allows the end user to turn text hiding off and on. When the checkbox is changed it seems like I should be able to use GUIwrite to do this, but I couldn't find a defined constant that reverses the effect of $ES_PASSWORD.

Thanks for any help!

john

Share this post


Link to post
Share on other sites

Likely you'll have to use GuiSendMsg and do some digging into the Windows API to find the proper message and WPARAM/LPARAM.

msdn.microsoft.com would be a good place to start and search for messages starting with EM_.

Share this post


Link to post
Share on other sites

That's just the hint I needed. Here's the code:

if (GUIread($chkbox_EnableClearText) == $GUI_CHECKED) then

GUISendMsg($pw1, 0x00CC,0, 0)

else

GUISendMsg($pw1, 0x00CC, 42, 0)

endif

GUIwrite($pw1, $GUI_FOCUS)

Focus has to be set to the input box before the characters are rewritten. 42 is ASCII for "*", you can use any character you want.

john

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Here's a cute trick to remove and replace the control with a new one. This can be used in any control, and I've used it before to change a tooltip (currently using GuiSetControlEx() will add a tooltip, not create one.) Another advantage is you don't need any focus on the object in question since it was re-created.

$GUI_HIDE = 32
$ES_PASSWORD = 0x0020

GuiCreate("Toggle Password Example", 200, 60)
  $show = GuiSetControl("checkbox", "Show Password", 0, 0, 100, 20, $ES_PASSWORD)
  $passBox = GuiSetControl("input", "", 0, 20, 200, 20)
    $checked = 0;lets us test the current state of the box against the last known state
  GuiSetControl("button", "Accept Password", 0, 40, 100, 20)
GuiShow()

While 1
  Sleep(50);don't kill the CPU
  $test_state = NOT BitAND(GuiRead($show), 4);sets 1 if not checked, 0 if checked
  If $test_state <> $checked Then SetState($test_state)
  If GuiMsg(0) = -3 Then Exit;catch the red exit button
WEnd

Func SetState($passState)
  $passState = $passState * $ES_PASSWORD;translate the paramater into state
  $currentPass = GuiRead($passBox)
  GuiSetControlEx($passBox, $GUI_HIDE);hide the passbox
  $passBox = GuiSetControl("input", $currentPass, 0, 20, 200, 20, $passState);create a new one
  $checked = NOT $checked;swap $checked state
EndFunc

Edit

Okay, I messed upt he not checked vs checked. 1 is not checked, and 0 is checked. The comment has been corrected.

Edited to remove the useless "divide by one" code.

Edited by pekster

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Share this post


Link to post
Share on other sites

@pekster

Thanks for the example. I've wondered about the function reference description for GUISetControl, "Create/update a control ..." I couldn't figure out the update part. Do you know if the memory allocated for the original control is made available for reuse?

john

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Do you know if the memory allocated for the original control is made available for reuse?

I don't know if the physical memory is freed or not (although the GuiDelete() command might be of interest to you) but I did find out that the return of the GuiSetControl() command is increased by one every time the input box in my example is re-created. So it's not being given the exact same control referance. I am tempted to say that it is not freed right away simply because the control is only in a hidden state. I'm not sure how to truely "delete" a single control without deleting the rest of the GUI resources like GuiDelete() does.

Another solution using my previous example would be to create only 2 input boxes (one with password chars, and another without) and then toggle the hide/ show states. You would also have to update the text with what the user had entered so far like I did. This would prevent any potential RAM loss due to an excessive amount of clicking.

Edited to correct (yet another) typo. I'm probably at an average of 0.75 typos per post :D

Edited by pekster

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Share this post


Link to post
Share on other sites

He has already solved the problem... Sending EM_PASSWORDCHAR or something to that effect with WPARAM set to >0 changes all characters to the specified character; passing 0 as the WPARAM removes the password character showing the original text.

Share this post


Link to post
Share on other sites

That cannot be used for my ToolTip issue that I resolved in another thread. I was posting my example not because I thought it was a better solution than the previous mention, but because it can eaisily be extended to other aspects that may not have a convient (or documented) windows API control method.


[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0