Also, a rather simpler bit of Windows API work… To suppress echo whilst password is typed, you can use a function like…
[code]function mySetConsoleMode ( bEchoState as boolean ) as boolean
// from example code at…
// http://msdn.microsoft.com/en-us/library/ms685035(v=vs.85).aspx
const Win32API_STD_INPUT_HANDLE = -10
const Win32API_ENABLE_ECHO_INPUT = 4
const Win32API_ENABLE_ECHO_INPUT_off_mask = &hFFFFFFFB
const Win32API_INVALID_HANDLE_VALUE = -1
soft declare function Win32API_GetStdHandle lib “Kernel32.dll” alias “GetStdHandle” ( byval nStdHandle as int32 ) as int32
soft declare function Win32API_GetConsoleMode lib “Kernel32.dll” alias “GetConsoleMode” ( byval nStdHandle as int32, byref dwMode as int32 ) as int32
soft declare function Win32API_SetConsoleMode lib “Kernel32.dll” alias “SetConsoleMode” ( byval nStdHandle as int32, byval dwMode as int32 ) as int32
// Keep old mode in a static variable…
static fdwSaveOldMode as int32
dim hStdIn as int32
dim dwNewMode as int32
dim i32Result as int32
// Get the standard input handle.
hStdIn = Win32API_GetStdHandle( Win32API_STD_INPUT_HANDLE )
if hStdIn = Win32API_INVALID_HANDLE_VALUE then
print “Failed to get handle”
RETURN ( false )
end if
// Set new echo state…
if bEchoState then
dwNewMode = fdwSaveOldMode
else
// Save the current input mode, restored by resetting echo to ON
i32Result = Win32API_GetConsoleMode( hStdIn, fdwSaveOldMode )
if i32Result <> 1 then
print "Failed to get mode: " + str( i32Result )
RETURN ( false )
end if
dwNewMode = fdwSaveOldMode AND Win32API_ENABLE_ECHO_INPUT_off_mask
end if
// Set this mode…
i32Result = Win32API_SetConsoleMode( hStdIn, dwNewMode )
if i32Result <> 1 then
print "Failed to set mode: " + str( i32Result )
RETURN ( false )
end if
RETURN ( true )[/code]
Then call it like:-
[code]dim strPwd as string
dim bResult as boolean
print “Try with no mods”
print “Enter password:”
strPwd = input
print " pwd=" + strPwd
print “Try with NO ECHO”
print “Enter password:”
bResult = mySetConsoleMode( false )
strPwd = input
print " pwd=" + strPwd
bResult = mySetConsoleMode( true )
[/code]
This works OK in my test on windows XP just now.