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

Is there any way we can prompt a user for a password when he executes a .pl file? Correct password is entered, .pl file executes.

Alternatively suppose in a top level Perl Tk window, a user clicks an OK button to get to the next window(the first screen of the application).Only before he is presented with the next window, he should be prompted to enter a password. How do we do this in Perl/Tk?

Replies are listed 'Best First'.
Re: Password question
by Anonymous Monk on Aug 13, 2009 at 11:50 UTC
Re: Password question
by alexm (Chaplain) on Aug 13, 2009 at 14:33 UTC

    What are you trying to achive with that password? Forbid the user to execute the script? Since Perl scripts have to be readable in order to be executable, a smart user could copy the script, remove the part requesting a password and then execute it.

    OTOH, you could jail the script with permissions and a suid/sgid wrapper in C, but maybe this is too overkill depending on what you want.

Re: Password question
by bichonfrise74 (Vicar) on Aug 13, 2009 at 16:14 UTC
    Why can't you use something like this? Although the user can see the password if he opens the script.
    #!/usr/bin/perl use strict; print "Enter password: \n"; chomp( my $answer = <> ); die "Incorrect password.\n" if ( $answer eq 'password' ); # ... main program is here #