Quick test professional

QTP Tips QTP codes QTP Faqs and more

Prompt for password entry and hide while it is being typed

some times we need to prompt input box for a password and we need to  hide a password while it is being typed.
 But it is not possible with normal VBScript . we can use the AOM for IE with VBScript to do this.

Following is the code

strPw = GetPassword( “Please enter your password:” )
msgbox  “Your password is: ” & strPw

Function GetPassword( myPrompt )
‘ This function uses Internet Explorer to
‘ create a dialog and prompt for a password.

    Dim objIE
    ‘ Create an IE object
    Set objIE = CreateObject( “InternetExplorer.Application” )
    ‘ specify  the IE  settings
    objIE.Navigate “about:blank”
    objIE.Document.Title = “Password”
    objIE.ToolBar        = False
    objIE.Resizable      = False
    objIE.StatusBar      = False
    objIE.Width          = 300
    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
  
    ‘ 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
    ‘ Wait till the OK button has been clicked
    Do While objIE.Document.All.OK.Value = 0
        WScript.Sleep 200
    Loop
    ‘ 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

The code will create the screen like this

ie_password_dialog.gif

Author: Robvan der Woude

Advertisements

February 15, 2008 - Posted by | Uncategorized, VBScript and IE Automation | , , ,

7 Comments »

  1. Another thing i would like to ask you that “Do you have some idea about how to use QTP on mainframes? I am a project manager here on a mainframe project and we are planing to get do automation using QTP. I will greatly appriciate your help

    Comment by Pari | March 5, 2008 | Reply

  2. Pari,
    You have to use TE(Terminal Emulator)Addin for that.You have to buy that seperatly.

    Comment by quicktestprofessional | March 6, 2008 | Reply

  3. When I am using IE.Visible = TRUE, Application displays for a sec and disapperas,Is there ay method to display the form

    Comment by pooja | July 6, 2008 | Reply

  4. Very usefull. Thank you for taking the time to share.

    -O

    Comment by OingoBo | December 9, 2008 | Reply

  5. Dear,
    I have this below password. it is working good. but the problem is when it ask for password and when i type password the text show in the box is visible. it should come in “******” form. just guide me how can i edit this code to get password like this.
    thanks

    Private Sub CommandButton2_Click()
    If MsgBox(“Are you sure(You have to enter a correct password otherwise this workbook will be closed) ?”, vbYesNo + vbQuestion) = vbNo Then
    Exit Sub
    Else
    ‘Code goes here
    Dim pass As String
    pass = InputBox(“Enter Password”)
    If pass “sulaiman” Then ThisWorkbook.Close Saved = True
    Unload Me
    End If

    End Sub

    Comment by Usman | July 16, 2009 | Reply

  6. Just thank you, fully working 🙂

    Comment by Mat | November 10, 2011 | Reply

  7. Very helpful, thanks for sharing

    Comment by Ganesh | August 26, 2016 | Reply


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: