: : what i want to try and do is cover up the password with *. for
: : instance when you are entering in the password insteaded of seeing
: : 'program' you would see '*******'. is it possible to do it with only
: : using crt? i havent learnt anything else yet. im a noob at pascal.
: :
: : this is my program:
: :
: :
: :
: : program password_program;
: : uses crt;
: : var
: : password:string;
: : ch : char ;
: :
: : label pass;
: : label correct;
: : label wrong;
: : label quit;
: :
: : begin
: : pass:
: : clrscr;
: : writeln('please enter correct password:');
:
: password := '' ; { nul string }
: {
: readkey does not echo
: }
: ch := readkey ; { get first character ]
: while ord(ch) <> 13 do begin { "ENTER" key exits loop }
: password := password + ch ;
: write ('*') ; { fake echo }
: ch := readkey { get next character }
: end ;
: writeln ; { fake an echo of the "ENTER" key }
:
: :
: : if password='program' then goto correct else goto wrong;
: :
: : correct:
: : writeln('correct password! you may continue.');
: : readln;
: : goto quit;
: :
: : wrong:
: : writeln('bad password! try again!');
: : readln;
: : goto pass;
: :
: : quit:
: : end.
: : : :
:
:
This supports Backspace is case you mistyped :)
uses crt;
var pwd:string;
function get_pwd(mask:char):string; {mask can be any printable character}
var ch:char;
s:string;
begin
write('Enter password: ');
s:=''; {password set ot nil}
repeat
ch:=readkey; {read a key}
case ord(ch) of
8:{BckSp} if length(s)>0 then begin
gotoxy(pred(wherex),wherey); {move cursor to left}
write(#32); {print space to erase last char.}
gotoxy(pred(wherex),wherey); {move cursor to left}
if length(s)=1 then s:='' else s:=copy(s,1,pred(length(s)));
{if password length is 1 then set password to nil}
end else write(#7); {Beeps if 0 length}
32..127:{Spc..~}if length(s)<255 then begin
s:=s+ch;
write(mask);
end else write(#7);
end;
until ord(ch)=13; {Enter}
writeln; {CR+LF}
get_pwd:=s;
end;
begin
pwd:=get_pwd('*');
writeln('Password is: ',pwd);
end.