Console App: hiding password input text??

Everything else that doesn't fall into one of the other PB categories.
Paul Dwyer
User
User
Posts: 44
Joined: Wed Nov 05, 2003 4:34 am
Location: Tokyo, Japan

Console App: hiding password input text??

Post by Paul Dwyer »

I have an ODBC consol application and it asks a user for a username and password. When the user types their password to be caught by the input() statement it's visible on screen but I'd like to have it appear as *****

How can I do this?

The only way of hiding it I can think of is setting the font colour to the background colour so it's invisible... not quite what I want though

Thanks
Paul Dwyer
Network Engineer
Aussie in Tokyo
LarsG
Enthusiast
Enthusiast
Posts: 713
Joined: Mon Jun 02, 2003 1:06 pm
Location: Norway
Contact:

Post by LarsG »

Perhaps catch each keypress in a loop, then adding it to a string, and displaying it as *'s?!?

-Lars

AMD Athlon XP2400, 512 MB RAM, Hercules 3D Prophet 9600 256MB RAM, WinXP
PIII 800MHz, 320 MB RAM, Nvidia Riva Tnt 2 Mach 64 (32MB), WinXP + Linux
17" iMac, 1.8 GHz G5, 512 MB DDR-RAM, 80 GB HD, 64 MB Geforce FX 5200, SuperDrive, OSX
talun
User
User
Posts: 28
Joined: Mon May 05, 2003 3:53 pm
Location: Italy

Post by talun »

Paul, is this rusty routines useful for you?

Code: Select all

; masked password input
; not for extended chars
If OpenConsole() 
  PrintN("Password please: (return to exit)")
  Passwd$ = ""
  Repeat 
    xkey$ = Inkey() 
    If xkey$ <> "" 
      If Asc(xkey$)>=32 And Asc(xkey$) < 128 
        Passwd$ = Passwd$ + Left(xkey$, 1)
        Print("*")
      EndIf
    EndIf  
  Until Left(xkey$, 1) = Chr(13)      
  PrintN("")
  PrintN(Passwd$)
  t$=Input()
  CloseConsole() 
EndIf 
End 
bye Sergio
Paul Dwyer
User
User
Posts: 44
Joined: Wed Nov 05, 2003 4:34 am
Location: Tokyo, Japan

Post by Paul Dwyer »

Thanks!

That sort of points me in the right direction. I want people to be able to backspace so I'll have to catch that.

Is there a way to catch the current location of the cursor on the screen so I can decriment it and move it back a place. I know I can set it's location but if I don't know where it is then I can't move it in relation to that...
Paul Dwyer
Network Engineer
Aussie in Tokyo
plouf
Enthusiast
Enthusiast
Posts: 281
Joined: Fri Apr 25, 2003 6:35 pm
Location: Athens,Greece

Post by plouf »

whats wrong with #PB_String_Password in StringGadget :?:
Christos
Seldon
Enthusiast
Enthusiast
Posts: 405
Joined: Fri Aug 22, 2003 7:12 am
Location: Italia

Post by Seldon »

To know the current position, you can use a variable counter. Each time a letter is added you inc 1 to such variable, so you know where your cursor is. :P

Anyway, just for knowlegde, you can use the Win-API to know the current cursor position, look at this code (you can do a PB version in 3 seconds):

Code: Select all

HANDLE  hStdOut;
CONSOLE_SCREEN_BUFFER_INFO  csbi;

hStdOut=GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hStdOut,&csbi);
return csbi.dwCursorPosition.Y+1;
Basically the CONSOLE_SCREEN_BUFFER_INFO structure contains the X;Y values of your cursor:

x=csbi.dwCursorPosition.X
y=csbi.dwCursorPosition.Y

Though I'd suggest you to use a simple counter.
Paul Dwyer
User
User
Posts: 44
Joined: Wed Nov 05, 2003 4:34 am
Location: Tokyo, Japan

Post by Paul Dwyer »

Thanks Seldon!

Plouf, Because it's a consol application not a windows application
Paul Dwyer
Network Engineer
Aussie in Tokyo
Post Reply