InputBox for Password

 

 

The insert of a Password in a window is always masked with special characters such as asterisk(*), umlauts (~), spiral (@) or point.

 

Vbs to accept user input use the InputBox Function. This action shows a Popup with an area for the keyboard input (TextBox). This function however haven't a parameter that means the text must be "crypted". To achieve this scope it is possible simulate the InputBox function creating a DialogBox consists of an area that will contain the crypted text.

 

DialogBox will be created as an InternetExplorer Application. It will be a browser that consist on an Input Area of type Password.

 

I found this code on the net so it is NOT mine. Here it is:

 

'*************************************************

'**********************  M A I N ********************

'*************************************************

Dim strPW

strPW = GetPassword("Insert the Password: ")

msgbox "Your password is: " & strPW

'*************************************************

'**************   E N D     M A I N  ********************

'*************************************************

 

 

'*************************************************

'**********        GetPassword Function           ************

'*************************************************

Function GetPassword( myPrompt )
' This function uses Internet Explorer to
' create a dialog and prompt for a password.
'
' Argument:   [string] prompt text, e.g. "Please enter password:"
' Returns:    [string] the password typed in the dialog screen
'
' Written by Rob van der Woude
' http://www.robvanderwoude.com
' Error handling code written by Denis St-Pierre

    Dim objIE
    ' Create an IE object
    Set objIE = CreateObject( "InternetExplorer.Application" )
    ' specify some of the IE window's settings
    objIE.Navigate "about:blank"
    objIE.Document.Title = "Form to insert Password" & String( 100, vbTab )
    objIE.ToolBar        = False
    objIE.Resizable      = False
    objIE.StatusBar      = False
    objIE.Width          = 320
    objIE.Height         = 180
    ' Center the dialog window on the screen
    With objIE.Document.ParentWindow.Screen
        objIE.Left = (.AvailWidth  - objIE.Width ) \ 2
        objIE.Top  = (.Availheight - objIE.Height) \ 2
    End With

    ' Wait till IE is ready
    Do While objIE.Busy
        WScript.Sleep 200
    Loop

    ' Insert the HTML code to prompt for a password
    objIE.Document.Body.InnerHTML = "<DIV ALIGN=""center""><P>" & myPrompt _
                                  & "</P>" & vbCrLf _
                                  & "<P><INPUT TYPE=""password"" SIZE=""20"" " _
                                  & "ID=""Password""></P>" & vbCrLf _
                                  & "<P><INPUT TYPE=""hidden"" ID=""OK"" " _
                                  & "NAME=""OK"" VALUE=""0"">" _
                                  & "<INPUT TYPE=""submit"" VALUE="" OK "" " _
                                  & "OnClick=""VBScript:OK.Value=1""></P></DIV>"

    ' Make the window visible
    objIE.Visible = True

 

    objIE.Document.All.Password.Focus

 

    ' Wait till the OK button has been clicked
    On Error Resume Next
    Do While objIE.Document.All.OK.Value = 0
        WScript.Sleep 200

        ' Error handling code by Denis St-Pierre
        If Err Then    'user clicked red X (or alt-F4) to close IE window
            IELogin = Array( "", "" )
            objIE.Quit
            Set objIE = Nothing
            Exit Function
        End if
    Loop
    On Error Goto 0

    ' Read the password from the dialog window
    GetPassword = objIE.Document.All.Password.Value

    ' Close and release the object
    objIE.Quit
    Set objIE = Nothing
End Function

'*************************************************

 

______________________________________________________________________

 

Pag: >    >>