http://www.perlmonks.org?node_id=11110465

docsnyder has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks!

I am using Prima for creating GUI's and I am trying to handle a password input field with characters entered shown as '*'.

I have figured out, that this is achieved by setting the attribute 'writeOnly' of the InputLine to 'true'. But, how can I access the entered password in clear text in order to process it? Accessing it via the 'text()' method just return the hidden password (e.g. '*******'). Even setting 'writeOnly' to 'false' does not show the characters entered before in 'asterisk mode' in clear text.

I have stufied the Prima example menu.pl, but even with this example I am not able to retrieve clear text from the input field, once the characters have been asterisked.

Any experience/idea?. Any hint would be appreciated!

Regards
DocSnyder

  • Comment on GUI question: Prima: password input fields

Replies are listed 'Best First'.
Re: GUI question: Prima: password input fields
by roboticus (Chancellor) on Dec 21, 2019 at 13:56 UTC

    docsnyder:

    I've installed Prima years ago, but never got around to trying it out. (It's still on my To-Do list.)

    But in the installation is an examples directory, so I looked around in there. If you take a look at the examples/menu.pl script, it shows how you can use the password mode on an input control. I just ran it, and it worked just fine, so give it a look.

    You'll also want to look over the other examples when you're trying to figure out a feature. You might also look over the tests as well--I do that in any case for modules when I'm trying to figure out how to make something work.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Re: GUI question: Prima: password input fields
by Anonymous Monk on Dec 21, 2019 at 12:57 UTC

    subclass and override sub edit_text

    sub edit_text { my ($self, $text) = @_; $self->{password} = $text; $self-> begin_undo_group; $self-> push_undo_action( 'edit_text', $self->text); $self-> text($text); $self-> end_undo_group; }

    or patch

    $self->{password} = $cap; $cap = $self-> {passwordChar} x length $cap if $self-> {writeO +nly}; $self-> {wholeLine} = $cap;