john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

Perl readchar stdin password ascii string as chars

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/perl
use strict;
use warnings;
use Term::ReadKey;

# sudo apt-get install libterm-readkey-perl

my $key;
my $password;

print "Enter your password: ";

ReadMode(4); # Turn off controls keys

while( ord( $key = ReadKey(0)) != 10 )  # read keys until enter key
{

  # For all value of ord($key) see http://www.asciitable.com/
    if(ord($key) == 127 || ord($key) == 8)
    {
      # DEL/Backspace was pressed , Remove the last char from the password
      chop($password);
      #2 move the cursor back by one, print a blank character, move the cursor back by one
      print "\b \b";
    }elsif( ord($key) < 32 )
    {   # Do nothing with these control characters
    }else
    {
      $password = $password.$key;
      print "*";
#      print "*(".ord($key).")";
    }
}
ReadMode(0); #Reset the terminal once we are done
print "\n\nYour super secret password is: $password\n";

my $char;
foreach $char( split //, $password )
{
  print ord($char) . "\n";
}

  • « todo 0.1
  • Ubuntu base image hardening »

Published

Apr 27, 2012

Category

bat-vbs-perl

~156 words

Tags

  • as 12
  • ascii 4
  • bat-vbs-perl 51
  • chars 5
  • password 10
  • perl 14
  • readchar 1
  • stdin 2
  • string 18