[comp.lang.pascal] "Dots will echo: " for passwords...

garay@hyper.lap.upenn.edu (John Garay) (04/10/91)

I'm interested in a procedure in TP which will echo dots to the screen instead
of the actual keys pressed.  In other words, one of the ol'
	'Please type in password (dots will echo):'
types of things.  The form I have now (w/ the password broadcasted on the
screen is: 	clrscr;
		writeln ('Please Type Password:');
		readln (password);

I figure somewhere between the writeln and the readln there's got to be a way
to make dots echo instead of the (secret) password.  Any ideas, anyone?
A little background:  IBM TP3.01 (WAIT!  I'm interested in ideas with any
TP version!).    Thanks much for the help....
******************************************************************************

    John Garay            e-mail  :  garay@hyper.lap.upenn.edu
		          Office phone :  (215)  898-1954
			  Home Phone   : (215)  382-4102
			  Donations    :  4034 Walnut, Philly, PA   19104

"Change the Way People think, and things will Never be the Same."  S. Biko

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

	

cs202216@marmaduke.acslab.umbc.edu (cs202216) (04/10/91)

In article <40822@netnews.upenn.edu> garay@hyper.lap.upenn.edu (John Garay) writes:
>
>I'm interested in a procedure in TP which will echo dots to the screen instead
>of the actual keys pressed.  In other words, one of the ol'
>	'Please type in password (dots will echo):'
>types of things.  The form I have now (w/ the password broadcasted on the
>screen is: 	clrscr;
>		writeln ('Please Type Password:');
>		readln (password);
>
>I figure somewhere between the writeln and the readln there's got to be a way
>to make dots echo instead of the (secret) password.  Any ideas, anyone?
>A little background:  IBM TP3.01 (WAIT!  I'm interested in ideas with any
>TP version!).    Thanks much for the help....
>******************************************************************************
>
>    John Garay            e-mail  :  garay@hyper.lap.upenn.edu
>		          Office phone :  (215)  898-1954
>			  Home Phone   : (215)  382-4102
>			  Donations    :  4034 Walnut, Philly, PA   19104
>
>"Change the Way People think, and things will Never be the Same."  S. Biko
>
>******************************************************************************
>
>	

	To do this, you'll have to write a procedure to replace the readln
procedure.

example:

	Procedure GetPassword(var s : string);
	const
		bs  = #8;
		cr  = #13;
		esc = #27;
		bell = #7;
	var
		ch : char;
	begin
	s:='';
	repeat
	if keypressed then
		begin
		ch:=readkey;
		case ch of
			bs : begin
				if length(s) > 0 then
					begin
					delete(s,length(s),1);
					write(bs+' '+bs);
					end
				else
					write(bell);
			     end;
			cr : begin
			     end;
		        esc : begin
				{ If escape is pressed, clear the input }
				while length(s) > 0 do
				   begin
				   write(bs+' '+bs);
				   delete(s,length(s),1);
				   end;
			      end;
			else
				begin
				s:=s+ch;
				write('.');
				end;
			end;

	until ch = cr;
	writeln;
	end;


Hope this helps.


Matt Gove
Internet: cs202216@umbc5.umbc.edu

ehill@ziggy.austin.ibm.com (04/11/91)

In article <40822@netnews.upenn.edu> garay@hyper.lap.upenn.edu (John Garay) writes:
>
>I'm interested in a procedure in TP which will echo dots to the screen instead
>of the actual keys pressed.  In other words, one of the ol'
>	'Please type in password (dots will echo):'
>types of things.  The form I have now (w/ the password broadcasted on the
>screen is: 	clrscr;
>		writeln ('Please Type Password:');
>		readln (password);
>
>I figure somewhere between the writeln and the readln there's got to be a way
>to make dots echo instead of the (secret) password.  Any ideas, anyone?
>A little background:  IBM TP3.01 (WAIT!  I'm interested in ideas with any
>TP version!).    Thanks much for the help....
--------
Try this piece of (TP5.5) code for reading the password:

VAR
	password : string;
	ch : char;
	i : integer;

	i := 0;
	repeat
		ch := readkey;    {-I don't know if readkey exists in TP3.01}
		if ch <> #13 then
		begin
			inc(i);            {-increment string index counter}
			password[i] := ch; {-add char to password}
			write('.');        {-echo dot}
		end;
	until ch = #13; {-exit on carriage return}
	password[0] := chr(i); {-set stringlen byte }
---------
This is a very simple routine, it does not allow for backspacing.  I'll
leave that as an exercise for you.  Hope this helps you.

-
Ed Hill
Personal Programming Center - IBM Austin
Internet: ehill@wombat.austin.ibm.com
-

amb43790@uxa.cso.uiuc.edu (Anthony M Brummett) (04/11/91)

garay@hyper.lap.upenn.edu (John Garay) writes:


>I'm interested in a procedure in TP which will echo dots to the screen instead
>of the actual keys pressed.  In other words, one of the ol'
>	'Please type in password (dots will echo):'
>types of things.  The form I have now (w/ the password broadcasted on the
>screen is: 	clrscr;
>		writeln ('Please Type Password:');
>		readln (password);

>I figure somewhere between the writeln and the readln there's got to be a way
>to make dots echo instead of the (secret) password.  Any ideas, anyone?
>A little background:  IBM TP3.01 (WAIT!  I'm interested in ideas with any
>TP version!).    Thanks much for the help....
>******************************************************************************

>    John Garay            e-mail  :  garay@hyper.lap.upenn.edu
>		          Office phone :  (215)  898-1954
>			  Home Phone   : (215)  382-4102
>			  Donations    :  4034 Walnut, Philly, PA   19104

>"Change the Way People think, and things will Never be the Same."  S. Biko

>******************************************************************************

The way I've done it is to rewrite the readln procedure:
  (* ReadSecret is used in the same context as ReadLn except it returns only
     one string *)
  procedure ReadSecret(var s:string);
    var c:char;
    begin
      s:='';
      repeat
        c:=ReadKey;
        if c<>#13 then 
          s:=s+c;
      until c=#13;
    end;{ReadSecret}

This, of course, is only a bare bones routine and does not detect keys like   
backspace, but should get the job done.

Antoine---------------------------amb43790@uxa.cso.uiuc.edu
	

tritsche@Informatik.TU-Muenchen.DE (Stefan Tritscher) (04/13/91)

In article <40822@netnews.upenn.edu> garay@hyper.lap.upenn.edu (John Garay) writes:
>
>I'm interested in a procedure in TP which will echo dots to the screen instead
>of the actual keys pressed.  In other words, one of the ol'
>	'Please type in password (dots will echo):'
>types of things.  The form I have now (w/ the password broadcasted on the
>screen is: 	clrscr;
>		writeln ('Please Type Password:');
>		readln (password);
>
It is generally no good idea to print dots for every character of the
password, if you want the secret password to stay secret. Dots would be
helpful for an intruder, because he would know the length of the password.
Knowing the length of a passwords makes it much easier to break the
password, because the number of possible passwords is reduced.

My suggestion: don't echo anything!

It's a long time ago since I used TP, but I think in TP 3.x you can read
single characters without echo with: read(kbd,c) ( I don't remember if this
works with complete strings - may be that you have to write your own string
input procedure).

Good luck,

	Stefan