[fpc-pascal] Readln a password

James Richters james at productionautomation.net
Sun Nov 27 15:31:21 CET 2016


Here is how I read passwords... it generates a random character and displays
that so someone looking over your shoulder things those characters are the
password
It uses readkey which does not display on the screen, one character at a
time

Function Readpw:String;
Var
   Pwstring : String;
   pwchar   :Char;
Begin
   Randomize;
   Pwstring:='';
   Repeat
      Pwchar:=readkey;
      If PwChar<>#13 Then
         Begin
            pwstring:=pwstring+Pwchar;
            Write(chr(Random(77)+33))
         End;
   until pwchar=#13;
   Readpw:=pwstring;
end;

-----Original Message-----
From: fpc-pascal-bounces at lists.freepascal.org
[mailto:fpc-pascal-bounces at lists.freepascal.org] On Behalf Of Adriaan van Os
Sent: Sunday, November 27, 2016 8:24 AM
To: FPC-Pascal users discussions <fpc-pascal at lists.freepascal.org>
Subject: [fpc-pascal] Readln a password

I wonder what the recommended way is to readln a password from console, as a
standard Readln echoes the password.

1. SetConsoleMode seems to be Windows-specific

2. On Mac OS X, a loop with a Crt.ReadKey until char(13) works in
Terminal.app, but behaves strange in the Xcode Console window (more precise,
uses Crt doesn't seem to be compatible with the Xcode
Console)

3. On Mac OS X, executing '/bin/stty -echo' gives an error message 'stty:
stdin isn't a terminal' 
(both in Terminal.appand in the Xcode Console window)

4. I experimented with '/usr/bin/read -s -p Password:' but couldn't get it
working from FPC.

Regards,

Adriaan van Os
_______________________________________________
fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal




More information about the fpc-pascal mailing list