X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=blobdiff_plain;f=src%2FPVE%2FPTY.pm;h=e433c4ec442a6cfdd1fae24e242ce1432215b760;hp=1178ea7a2da01eb29e6b2373a50445197cdaa1ec;hb=e97f807c388c10250f442b1f16c5315df2ffc2af;hpb=140642513383dfcebe381761c19b6d6c871bbe2b diff --git a/src/PVE/PTY.pm b/src/PVE/PTY.pm index 1178ea7..e433c4e 100644 --- a/src/PVE/PTY.pm +++ b/src/PVE/PTY.pm @@ -165,7 +165,7 @@ sub tcsetsize($$$) { or die "failed to set window size: $!\n"; } -sub read_password(;$$) { +sub read_password($;$$) { my ($query, $infd, $outfd) = @_; my $password = ''; @@ -194,10 +194,13 @@ sub read_password(;$$) { syswrite($outfd, $query, length($query)); while (($got = sysread($infd, $ch, 1))) { my ($ord) = unpack('C', $ch); - if ($ord == 0xD) { + last if $ord == 4; # ^D / EOF + if ($ord == 0xA || $ord == 0xD) { # newline, we're done syswrite($outfd, "\r\n", 2); last; + } elsif ($ord == 3) { # ^C + die "password input aborted\n"; } elsif ($ord == 0x7f) { # backspace - if it's the first key disable # asterisks @@ -225,6 +228,13 @@ sub read_password(;$$) { return $password; } +sub get_confirmed_password { + my $pw1 = read_password('Enter new password: '); + my $pw2 = read_password('Retype new password: '); + die "passwords do not match\n" if $pw1 ne $pw2; + return $pw1; +} + # Class functions sub new {