Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi Konsolenanwendung Readln versteckt (https://www.delphipraxis.net/124603-konsolenanwendung-readln-versteckt.html)

hedie 21. Nov 2008 18:25


Konsolenanwendung Readln versteckt
 
Hallo

Wie kann ich in einer Konsolenanwendung das readln versteckt machen? also dass das eingegebene Passwort nicht direkt sichtbar ist.....

Danke schonmal

Grüsse
Claudio

Apollonius 21. Nov 2008 18:31

Re: Konsolenanwendung Readln versteckt
 
Du musst mit MSDN-Library durchsuchenSetConsoleMode einen neuen Input Mode setzen, in dem ENABLE_ECHO_INPUT nicht enthalten ist.

sirius 21. Nov 2008 19:01

Re: Konsolenanwendung Readln versteckt
 
@Ap
Und du bist dir sicher, dass readln da noch etwas empfängt.
Ah ja


Ich hab mal eine Funktioen mit Sternen als Platzhalter geschrieben:
Delphi-Quellcode:
function readPassword:string;
var HandleIn,HandleOut:THandle;
    key:char;
    temp:Cardinal;
    premode,mode:Cardinal;
    s:string;
    star:string;
begin
  star:='*'#8' '#8;
  HandleIn:=GetStdHandle(STD_INPUT_HANDLE);
  HandleOut:=GetStdHandle(STD_OutPut_HANDLE);
  getConsoleMode(handleIN,premode);
  mode:=premode and not (Enable_line_input or Enable_Echo_input);
  setconsolemode(handleIN,mode);
  FlushConsoleInputBuffer(HandleIN);
  result:='';
  repeat
    if (not ReadConsole(HandleIN,@key,1,temp,nil))or(temp<>1) then
      beep(410,100)
    else
    begin
      case ord(key) of
        32..126: begin
          result:=result+key;
          writeconsole(handleOut,@star[1],1,temp,nil);
        end;
        8: begin
          writeconsole(handleOut,@star[2],3,temp,nil);
          setlength(result,length(result)-1);
        end;
        13: writeln;
        else beep(410,100);
      end;
    end;
  until key=#13;
  setconsolemode(HandleIN,premode);
end;

Apollonius 21. Nov 2008 19:17

Re: Konsolenanwendung Readln versteckt
 
Ja, bin ich.


Alle Zeitangaben in WEZ +1. Es ist jetzt 08:45 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz