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
Console App: hiding password input text??
-
- User
- Posts: 44
- Joined: Wed Nov 05, 2003 4:34 am
- Location: Tokyo, Japan
Console App: hiding password input text??
Paul Dwyer
Network Engineer
Aussie in Tokyo
Network Engineer
Aussie in Tokyo
Perhaps catch each keypress in a loop, then adding it to a string, and displaying it as *'s?!?
-Lars
-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
Paul, is this rusty routines useful for you?
bye Sergio
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
-
- User
- Posts: 44
- Joined: Wed Nov 05, 2003 4:34 am
- Location: Tokyo, Japan
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...
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
Network Engineer
Aussie in Tokyo
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.
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):
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.

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;
x=csbi.dwCursorPosition.X
y=csbi.dwCursorPosition.Y
Though I'd suggest you to use a simple counter.
-
- User
- Posts: 44
- Joined: Wed Nov 05, 2003 4:34 am
- Location: Tokyo, Japan