Board index » delphi » Help with passwords??

Help with passwords??

Can someone give me some code that allows me to enter a password in *'s and
still be able to use the back space key, it is for a project a college.

thanx in advance
 Andrew

(PS im using the Dos version 7 of T.pascal)

TA! :-)

 

Re:Help with passwords??


Quote
> Can someone give me some code that allows me to enter a password in *'s and
> still be able to use the back space key, it is for a project a college.

   This should get you started:
procedure MyRead (var ST : string; Q : Byte);  { internal string }
var C1,C2 : char;
begin
  ST := '';                           { initialize string length }
  repeat
    C1 := ReadKey;
    case C1 of
      #27  : begin                                      { escape }
             end;
      #00  : C2 := ReadKey;                    { flush scan code }
      #13  : ;                                             { C/R }
      #08  : begin                                   { Backspace }
               if Length(ST) > 0 then
                 begin
                   Dec (ST[0]);                { truncate string }
                   Write (#08#32#08)
                 end;
             end;
      else   begin                            { normal character }
               ST := ST+C1;    { concatenate character to string }
               Write ('*')                         { echo an "*" }
             end
    end  { case }
  until (C1 = #13) or (Length(ST) >= Q)
end;  { MyRead }

Re:Help with passwords??


ta m8

Re:Help with passwords??


Hi

  Im fairly new to pascal, so maybe im missing something but wont this work better?

*************************************************************

procedure Readcr (var s : string);
var
        password : string;
                x,y,i : integer;
begin
        i := 0;
        repeat
                i := i + 1;
                x ;= wherex;
                y := wherey;
                password[i] := readkey;
                if  not (ord(password[i]) in [13,8]) then
                        write ('*')
                else if ord(password[i]) = 8 then
                begin
                        GotoXY(x-1,y);
                        ClrEol;
                        i := i - 2;
                end;
        until ord(password[i]) = 13;
        password[0] := chr(i);
        writeln;
        s := password;
end;

**********************************************************

Please tell me if this wont work. Thx.

Daniel Morton

Other Threads