1. Password prompt routine

Hello again folks!

Ok I've got a routine I've called "getpw".  You give it a prompt string, it
displays this prompt and then accepts a line of input which is terminated
when you press return.  The routine returns the typed line.  When you type
a character it prints a single '*' character so you know you've typed the
character but has the nice effect that what you type is hidden from prying
eyes.  Hence GET PassWord smile

I detect the backspace key (ASCII code 8) and deal with it accordingly
(i.e. throw away the last character typed).  I was hoping to print a
"backspace, space, backspace" sequence to rub out the last '*' character
but can't get this to work.  Instead I'm currently printing a '#' character
to indicate that the last character has been "erased".  If someone can help
me achieve the "backspace, space, backspace" effect I'm after I'd be very
grateful.

Regards.

FP.


function getpw(sequence prompt)
  sequence   pw
  integer    key
  integer    lenpw

  printf(1, "%s", {prompt})

  pw = ""

  while 1 do
    lenpw = length(pw)

    key = wait_key()

    if ( (key = 10) or (key = 13) ) then
      if lenpw > 0 then
        exit
      end if
    end if

    if ( (key = 8) or (key = 127) ) then
      if (lenpw > 0) then
        printf(1, "#", {})

        if (lenpw = 1) then
          pw = ""
        else
          pw = pw[2..lenpw]
        end if
      end if
    end if

    if ( (key >= 32) and (key <= 126) )
    then
      printf(1, "*", {})
      pw = append(pw, key)
    end if
  end while

  printf(1, "\n", {})

  return(pw)

end function


End of message.

new topic     » topic index » view message » categorize

2. Re: Password prompt routine

If you know the key values already which it sounds
like you do, why couldnt you trap the key presses
and process screen output based on the trapped key.

I had a demo for this very thing somewhere, I went looking
for it but it has misteriously been placed somewhere on
my HD but because I have no method for nameing things
it's lost at the moment.... hehe funny huh?

Euman
euman at bellsouth.net

----- Original Message ----- 
From: <freeplay at mailandnews.com>
To: "EUforum" <EUforum at topica.com>
Sent: Friday, August 17, 2001 18:00
Subject: Password prompt routine


> 
> Hello again folks!
> 
> Ok I've got a routine I've called "getpw".  You give it a prompt string, it
> displays this prompt and then accepts a line of input which is terminated
> when you press return.  The routine returns the typed line.  When you type
> a character it prints a single '*' character so you know you've typed the
> character but has the nice effect that what you type is hidden from prying
> eyes.  Hence GET PassWord smile
> 
> I detect the backspace key (ASCII code 8) and deal with it accordingly
> (i.e. throw away the last character typed).  I was hoping to print a
> "backspace, space, backspace" sequence to rub out the last '*' character
> but can't get this to work.  Instead I'm currently printing a '#' character
> to indicate that the last character has been "erased".  If someone can help
> me achieve the "backspace, space, backspace" effect I'm after I'd be very
> grateful.
> 
> Regards.
> 
> FP.
> 
> 
> function getpw(sequence prompt)
>   sequence   pw
>   integer    key
>   integer    lenpw
> 
>   printf(1, "%s", {prompt})
> 
>   pw = ""
> 
>   while 1 do
>     lenpw = length(pw)
> 
>     key = wait_key()
> 
>     if ( (key = 10) or (key = 13) ) then
>       if lenpw > 0 then
>         exit
>       end if
>     end if
> 
>     if ( (key = 8) or (key = 127) ) then
>       if (lenpw > 0) then
>         printf(1, "#", {})
> 
>         if (lenpw = 1) then
>           pw = ""
>         else
>           pw = pw[2..lenpw]
>         end if
>       end if
>     end if
> 
>     if ( (key >= 32) and (key <= 126) )
>     then
>       printf(1, "*", {})
>       pw = append(pw, key)
>     end if
>   end while
> 
>   printf(1, "\n", {})
> 
>   return(pw)
> 
> end function
> 
> 
> End of message.
> 
> 
> 
> 
>

new topic     » goto parent     » topic index » view message » categorize

3. Re: Password prompt routine

Hello again,

Thanks for all the suggestions.  In the end I worked out that a:

   printf(1, "\r", {})

puts the cursor back to the beginnning of the line.  So to erase the last
character printed I would need to goto the beginning of the line, print out
the line again but have the last character in the line be a space (to
erase) and then goto the beginning of the line again and reprint the line
minus the last character.  You can detect a bit of cursor flicker but it's
good enough for me smile

Here is the revised routine:

function getpw(sequence prompt)
  sequence   pw
  integer    key
  integer    lenpw

  printf(1, "%s", {prompt})

  pw = ""

  while 1 do
    lenpw = length(pw)

    key = wait_key()

    if ( (key = 10) or (key = 13) ) then
      if lenpw > 0 then
        exit
      end if
    end if

    if ( (key = 8) or (key = 127) ) then
      if (lenpw > 0) then
        if (lenpw = 1) then
          pw = ""
        else
          pw = pw[2..lenpw]
        end if

        lenpw = lenpw - 1

        printf(1, "\r%s", {prompt})
        for i = 1 to lenpw do
          printf(1, "*", {})
        end for
        printf(1, " ", {})

        printf(1, "\r%s", {prompt})
        for i = 1 to lenpw do
          printf(1, "*", {})
        end for
      end if
    end if

    if ( (key >= 32) and (key <= 126) ) then
      if (lenpw < MAXPWLENGTH) then
        printf(1, "*", {})
        pw = append(pw, key)
      end if
    end if
  end while

  printf(1, "\n", {})

  return(pw)

end function

At 00:00 18/08/01 +0100, I wrote:
>
>Hello again folks!
>
>Ok I've got a routine I've called "getpw".  You give it a prompt string, it
>displays this prompt and then accepts a line of input which is terminated
>when you press return.  The routine returns the typed line.  When you type
>a character it prints a single '*' character so you know you've typed the
>character but has the nice effect that what you type is hidden from prying
>eyes.  Hence GET PassWord smile
>
>I detect the backspace key (ASCII code 8) and deal with it accordingly
>(i.e. throw away the last character typed).  I was hoping to print a
>"backspace, space, backspace" sequence to rub out the last '*' character
>but can't get this to work.  Instead I'm currently printing a '#' character
>to indicate that the last character has been "erased".  If someone can help
>me achieve the "backspace, space, backspace" effect I'm after I'd be very
>grateful.
>
>Regards.
>
>FP.
<snipped>

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu