.

How to accept masked characters in an user created input box?

One of the LearnQTP readers asked this question:

Hi Ankur,

I need help with Input Box .
When I enter password in Inputox( Wpass = InputBox(”EnterPassword”)) its showing up the “password” instead of “********” ..we need to prompt input box for a password and we need to hide a password while it is being typed.Do you have solution for this ? I googled it I came up with VBScript..Is it possible with InputBox Function..

Now, as far as I know this can’t be handled either by using the built-in InputBox function or by using Crypt method.

For those who still wonder about the applicability of DotNetFactory, you can use it here.
Using Example-11 from one of our earlier posts on DotNetFactory, you can modify it and add UseSystemPasswordChar method to make sure the entered characters are masked. This is what the modified code would look like

Set MyForm = DotNetFactory.CreateInstance("System.Windows.Forms.Form", "System.Windows.Forms")

Set MyText = DotNetFactory.CreateInstance("System.Windows.Forms.TextBox", "System.Windows.Forms")

Set MyButton = DotNetFactory.CreateInstance("System.Windows.Forms.Button", "System.Windows.Forms")

Set Pos = DotNetFactory.CreateInstance("System.Drawing.Point"
,"System.Drawing",x,y)

Pos.X = 90
Pos.Y = 100
MyText.Location = Pos
MyText.Width = 100
MyText.UseSystemPasswordChar = true
Pos.X = 100
Pos.Y = 130
MyButton.Location = Pos
MyButton.Text = "Close"
MyForm.Controls.Add MyText
MyForm.Controls.Add MyButton
MyForm.CancelButton = MyButton
MyForm.ShowDialog

Msgbox MyText.Text

Set MyText = Nothing
Set MyButton = Nothing
Set Pos = Nothing
Set MyForm = Nothing

True property under MyText.UseSystemPasswordChar = true will make sure that the entered characters are masked and are not visible to the user.
Run the above piece of code and let me know if this worked for you.

Have you downloaded the FREE Optimizing QTP eBook yet? Get It Now!

If you want to keep track of further articles on QTP. I recommend you to subscribe via RSS feed. You can also subscribe by Email and have new QTP articles sent directly to your inbox.

Related posts:

  1. Part4: QTP and DotNetFactory – Creating Text Box, Check Box and Radio Button Control
  2. Part2: QTP and DotNetFactory – Creating a User Form
  3. Part3: QTP and DotNetFactory – Creating a Button Control
  4. Part5: QTP and DotNetFactory – Creating a Progress Bar Control
  5. Part1: QTP and DotNetFactory – Basics

4 comments ↓

#1 Shirish Deshpande on 01.05.10 at 12:08

In Vb script we use SetSecure to appear the password in ******* form.
Kindly check if there is any method for dot net available!

#2 vivek on 01.05.10 at 17:58

It was not working . While, running script QTP can’t recognized Object.Input ask for Type for password and after putting letter in Input box, it’s want not encrypted.
Please let me know the solution and correct script.

#3 vasu on 01.07.10 at 11:42

Don’t worry he will be fine. All our good wishes are with him.

#4 Jayachandra on 01.15.10 at 12:36

Hi Ankur,

I am looking for a concept “Broken Link” using descriptive programming” and how to test this for all the links .

Can you post the snippet for the following.

Thanxs in advance..

Leave a Comment