Changed to properly handle backspace when entering passwords
authorAndrew DeFaria <Andrew@DeFaria.com>
Fri, 16 Oct 2020 16:36:23 +0000 (09:36 -0700)
committerAndrew DeFaria <Andrew@DeFaria.com>
Fri, 16 Oct 2020 16:36:23 +0000 (09:36 -0700)
lib/Utils.pm

index 8aabcaa..29e020c 100644 (file)
@@ -341,10 +341,9 @@ Returns:
 
 =cut  
 
-  
   $prompt ||= 'Password';
 
-  my $password;
+  my $password = '';
 
   local $| = 1;
 
@@ -365,9 +364,18 @@ Returns:
        last;
     } # if
 
-    print '*';
+    # Handle backspaces
+    if ($key eq chr(127)) {
+      unless ($password eq '') {
+        chop $password;
+
+        print "\b \b";
+      } # unless
+    } else {
+      print '*';
 
-    $password .= $key;
+      $password .= $key;
+    } # if
   } # while
 
   ReadMode 'restore'; # Reset tty mode before exiting.