Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Drop-In Password Dialog?

by ColonelPanic (Friar)
on Nov 28, 2012 at 13:30 UTC ( #1006028=perlquestion: print w/ replies, xml ) Need Help??
ColonelPanic has asked for the wisdom of the Perl Monks concerning the following question:

Dear Fellow Monks,

I have scripts that connect to a database, and I want to let the user type a password without it being seen on the screen. I know this is a common issue, and the normal solutions are available all over the place (here, for example): either disable terminal echo with system commands, or use Term::ReadKey.

However, my problem is that I run my scripts in Eclipse (using the EPIC plugin). I/O goes through Eclipse's own terminal, which is not accesible through either of these methods.

I wondered if there was a module that creates a simple username/password dialog that could be added to a script in drop-in fashion, without me having to add a bunch of GUI handling to the script. This seems like an obvious, useful idea, but I wasn't able to find anything on CPAN.

Thanks in advance for your help.



When's the last time you used duct tape on a duct? --Larry Wall

Comment on Drop-In Password Dialog?
Download Code
Re: Drop-In Password Dialog?
by zentara (Archbishop) on Nov 28, 2012 at 15:40 UTC
    Any time you call a Tk script for example, your original script will continue to run after the MainLoop is destroyed. So you can just make your own little password popup like this:
    #!/usr/bin/perl use warnings; use strict; use Tk; my $mw = new MainWindow(); my $password = ''; my $entry = $mw->Entry( -show=>'*', -relief=>'ridge', -textvariable=>\$password )->pack; $entry->bind('<Return>',[\&somesub]); $entry->focus; # when the MainLoop is destroyed, the calling script can continue MainLoop; sub somesub { $password = $entry->get; print "password ->$password\n"; $mw->destroy; } print "you can continue on here\n"; <>; #wait for keypress to exit;

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
      Thanks, this looks like it will be very helpful!


      When's the last time you used duct tape on a duct? --Larry Wall

      zentara, thanks again for this useful solution. I modified it slightly to also get a username, and it works great!



      When's the last time you used duct tape on a duct? --Larry Wall
Re: Drop-In Password Dialog?
by tobyink (Abbot) on Nov 28, 2012 at 17:17 UTC

    I can't find any... which is a shame as it seems quite a useful sort of thing to do. Here's a quick stab at a module that can prompt the user for basic information such as passwords, text entry, file selection, etc.

    It provides two backends - one for STDIN/STDOUT, and one that uses the Gnome tool Zenity to provide GUI prompts. The choice of which backend is made automatically.

    # Usage... my $ask = Ask->new; say "GOT: ", $ask->entry(text => "Please enter your password!", hide_t +ext => 1);

    Anyone fancy implementing Tk or Wx backends?

    Update: now on Bitbucket and GitHub

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
      Thanks for putting so much work into this. It looks like a great module concept. I look forward to trying this out when I get back to work.


      When's the last time you used duct tape on a duct? --Larry Wall

        A developer release is on CPAN now... Ask-0.000_01.

        perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1006028]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2014-07-12 02:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (238 votes), past polls