{program na zadavanie utajenych retazcov

Jozef Sivek ml. ad. 21.5.2006
}
program password;
uses crt;

var in01,in02:string;
    pass:string;


procedure hiddenReadln(var str:string; ifshow:boolean);
          var input:char;
              out:string;
              position:integer;
          begin
          position:=0;
          out:='';

          repeat
          input:=readkey;
          if input<>#13 then begin
                          if ((input>='0') and (input<='9')) or
                             ((input>='A') and (input<='Z')) or
                             ((input>='a') and (input<='z')) or
                             (input=' ') or
                             (input='_') or
                             (input='-') or
                             (input='.') or
                             (input=',')
                                                       then begin
                                                       if position<255 then begin
                                                                            if ifshow then write('*');
                                                                            inc(position);
                                                                            out:=out+input;
                                                                            end;
                                                       end;
                          if (input=#8) and (position=0) then begin sound(500);delay(300);nosound; end;
                          if (input=#8) and (position>0) then begin
                                        if ifshow then begin
                                                       gotoxy(whereX-1,whereY);
                                                       clreol;
                                                       end;
                                        out:=copy(out,1,length(out)-1);
                                        dec(position);
                                        end;
                          end;

          if input=#13 then writeln;
          until input=#13;

          str:=out;
          end;

begin
clrscr;
in01:='';
in02:='';

repeat
      if in01<>in02 then writeln('   Heslo bolo zadane zle, zadajte ho prosim este raz...');
      write('Zadajte heslo:');
      hiddenReadln(in01,TRUE);
      write('Zadajte heslo znovu:');
      hiddenReadln(in02,TRUE);
until in01=in02;

pass:=in01;
in01:='';
in02:='';

writeln('Heslo je: "',pass,'"');
repeat
      write('pre ukoncenie programu zadajte heslo:');
      hiddenReadln(in01,TRUE);
      if in01<>pass then writeln('   Heslo bolo zadane zle!');
until in01=pass;

end.
