home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / share / Dos / VARIOS / pascal / ENTRY.SWG / 0003_Password Routines.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1996-02-21  |  3.4 KB  |  116 lines

  1. {
  2. CS>I need to put a input inside a repeat loop to enter a password, but don't
  3. CS>want it to show what the user is typing, but rather show a different
  4. charactCS>say the charcter ' ' or any character that i can define.
  5.  
  6. Here you go...  here is some tested source code:
  7.  
  8.  
  9. {Scott Mitchell...   1996}
  10.  
  11. program Password_Program;
  12. uses crt;
  13. const TAB=9;  BACKSPACE=8;  ENTER=13;
  14. var password:string;
  15.  
  16. {--------------------------------------------------------------------------}
  17.  
  18. procedure ClearKeyboardBuffer;
  19. begin
  20.     MEM[$0040:$001A]:=MEM[$0040:$001C];     {Clears Keyboard Buffer!}
  21. end;
  22.  
  23. {--------------------------------------------------------------------------}
  24.  
  25. function LChar(s:char):char;
  26. {This is the opposite of the function UPCASE(char).  This simply turns
  27. a character into a lowercase character.}
  28. begin
  29.     if (ord(s)>=65) and (ord(s)<=90) then
  30.            s:=chr(ord(s)+32);
  31.     lchar:=s;
  32. end;
  33.  
  34. {--------------------------------------------------------------------------}
  35.  
  36. procedure GetInput(var s:string; filler:char; capital:boolean);
  37. {This procedure gets input from the user, and saves the response as the
  38.  string S.  Filler is the character you want to "mask" the actual typing.
  39. If you don't want the entry masked, just enter a ' ' in the procedure
  40. decleration.  Capital is a boolean value (TRUE/FALSE) which, if declared
  41. TRUE, forces Capitalization.  What this means, is that if the user types
  42. in his response, it capitalizes the first letter automatically and makes
  43. the rest lowercase.}
  44. var done:boolean;
  45.    ch:char;
  46.    temp,count,x,y:byte;
  47.    reply:packed array[0..255] of char;
  48. begin
  49.     ClearKeyboardBuffer;
  50.     x:=wherex;  y:=wherey;
  51.     count:=0;   done:=false;
  52.  
  53.     repeat
  54.     repeat until keypressed;
  55.     ch:=readkey;
  56.     case ord(ch) of
  57.          Enter:begin
  58.                  done:=true;
  59.                  reply[0]:=chr(count);
  60.             end;
  61.          Tab:begin
  62.                 if not(count>245) then begin
  63.                    inc(x,5);
  64.                    gotoxy(x,y);
  65.                    for temp:=1 to 5 do
  66.                        reply[count+temp]:=' ';
  67.                    inc(count,5);
  68.                 end;
  69.            end;
  70.          BackSpace:begin
  71.                 if not(count=0) then begin
  72.                    reply[count]:=' ';
  73.                    dec(count);
  74.                    dec(x);
  75.                    gotoxy(x,y);
  76.                    write(' ');
  77.                    gotoxy(x,y);
  78.                 end;
  79.            end;
  80.          else
  81.              begin
  82.                 inc(count);  inc(x);
  83.                 if (filler<>' ') and (ch<>' ') then
  84.                    write(filler)
  85.                 else
  86.                    if capital then begin
  87.                         if count>1 then
  88.                            if reply[count-1]=' ' then
  89.                               write(upcase(ch))
  90.                            else write(lchar(ch))
  91.                         else
  92.                             write(upcase(ch));
  93.                    end
  94.                    else write(ch);
  95.                 reply[count]:=ch;
  96.              end;
  97.     end;
  98.     until done;
  99.  
  100.     for x:=1 to ord(reply[0]) do
  101.         s:=s+reply[x];
  102. end;
  103.  
  104. {--------------------------------------------------------------------------}
  105.  
  106. begin
  107.     clrscr;
  108.     getinput(password,'*',false);
  109.     writeln; writeln;
  110.     write('You entered the password ',password);
  111.     readln
  112. end.
  113.  
  114. {============================== CUT HERE ============================}
  115.  
  116.