Passworteingabe mit Perl
Alexander Reelsen
ref at tretmine.org
Wed Feb 19 09:22:02 CET 2003
On Wed, Feb 19, 2003 at 09:11:24AM -0000, Arnd Behring wrote:
> ich habe folgendes Problem: Ich möchte in der Konsole ein Passwort abfragen.
> Das Problem ist nur, dass man es nicht sehen können soll. Da aber die
> Abfrage von <STDIN> das Script solange unterbricht, bis der Benutzer Return
> drückt, macht dies natürlich das Senden etwa von Backspace nach jedem
> Tastendruck unmöglich. Kennt irgendwer eine Funktion oder ein Modul, mit dem
> man Passwörter (halbwegs sicher) abfragen kann oder den Tastaturinput nach
> jedem Tastendruck? Zur Not ginge auch ein C/C++ Programm, dass vom Script
> aufgerufen wird, nach dem Passwort fragt und dies dann als Rückgabewert
> zurück gibt.
perldoc -q password
How do I ask the user for a password?
(This question has nothing to do with the web. See a dif-
ferent FAQ for that.)
There's an example of this in the crypt entry in the perl-
func manpage). First, you put the terminal into "no echo"
mode, then just read the password normally. You may do
this with an old-style ioctl() function, POSIX terminal
control (see the POSIX manpage or its documentation the
Camel Book), or a call to the stty program, with varying
degrees of portability.
You can also do this for most systems using the
Term::ReadKey module from CPAN, which is easier to use and
in theory more portable.
use Term::ReadKey;
ReadMode('noecho');
$password = ReadLine(0);
wenn du das modul nich nehmen willst, guck unter perlfunc -> crypt nach,
da stehts mit shell befehlen.
MfG/Regards, Alexander
--
Alexander Reelsen http://tretmine.org
ref at tretmine.org
More information about the Linux
mailing list