Here's a working solution:
program Project2;
{$APPTYPE CONSOLE}
uses
SysUtils, Windows;
function GetPassword(const InputMask: Char = '*'): string;
var
OldMode: Cardinal;
c: char;
begin
GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), OldMode);
SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), OldMode and not (ENABLE_LINE_INPUT or ENABLE_ECHO_INPUT));
try
while not Eof do
begin
Read(c);
if c = #13 then // Carriage Return
Break;
Result := Result + c;
if c = #8 then // Back Space
Write(#8)
else
Write(InputMask);
end;
finally
SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), OldMode);
end;
end;
begin
try
Writeln(Format(sLineBreak + 'pswd=%s',[GetPassword]));
Readln;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
Update: Note that the above code handles the BackSpaces visually, but keeps them embedded in the password, which might not be what you want.
In that case the following code would filter them out:
if c = #13 then // Carriage Return
Break;
if (c = #8) and (Length(Result) > 0) then // Back Space
begin
Delete(Result, Length(Result), 1);
Write(#8);
end
else
begin
Result := Result + c;
Write(InputMask);
end;