sid_com
sid_com

Reputation: 25117

IO::Prompter - Is it possible to disable history?

Is it possible - when prompting for a password - to configure prompt from IO::Prompter in a way that the input is not added to the history?

#!/usr/local/bin/perl
use warnings;
use strict;
use 5.10.1;
use utf8;
use open qw( :encoding(UTF-8) :std );
use IO::Prompter;


my $password = prompt( 'Password: ', -echo => '' );
say $password;
$password = prompt( 'Password: ', -echo => '' );
say $password;
$password = prompt( 'Password: ', -echo => '' );
say $password;
$password = prompt( 'Password: ', -echo => '' );
say $password;
$password = prompt( 'Password: ', -echo => '' );
say $password;

Upvotes: 3

Views: 395

Answers (2)

Bribles
Bribles

Reputation: 948

It was not possible when you wrote the question, but IO::Prompter has been patched to include the special history set NONE which disables the history.

The first version of IO::Prompter with the patch is 0.004003.

http://search.cpan.org/~dconway/IO-Prompter-0.004003/lib/IO/Prompter.pm

my $password = prompt('Password: ', -hNONE, -echo => '');

my $force_the_user_to_type = prompt('Type something: ', -hNONE);

Upvotes: 1

squiguy
squiguy

Reputation: 33380

If you are open to using other modules, I suggest Term::ReadKey

Here is a sample script I wrote that will disable echo for reading, read a line and return what it received for testing purposes.

#!/usr/bin/perl

use strict;
use warnings;
use Term::ReadKey;

ReadMode 2;
my $pw;
print "Enter password ";
while ( not defined( $pw ) ) {
  $pw = ReadLine(-1); 
}
chomp $pw;
print "\nI got $pw entered\n";
ReadMode 0;

Upvotes: 1

Related Questions