This is default featured slide 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Detailed Software Testing Tutorials and Interview Questions.

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Detailed Software Testing Tutorials and Interview Questions.3

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Detailed Software Testing Tutorials and Interview Questions.3

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Detailed Software Testing Tutorials and Interview Questions.3

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Detailed Software Testing Tutorials and Interview Questions.3

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Monday 27 February 2012

How to Decrypt an Encrypted Password in QTP


To encode or encrypt a password, QTP provides Encrypt method and Password Encoder tool. But what happens when a user wants to find out the decrypted (original) value of an encrypted password? QTP doesn’t provide a direct way to obtain the decrypted/decoded password.

The only method available is the SetSecure method which internally decrypts the value and sets it in the password fields.

The trick here is to use SetSecure method to decrypt the password but instead of entering the decrypted value in a password field (which displays text as ***), we will enter the value in a normal text field (which will display the text to the user in readable format). Lets see how this can be done.

Our Approach to Decrypt Password (In Brief)

a) Encrypt a password.
b) Create a VBScript InputBox.
c) Use the SetSecure method to write the decrypted value in the text field inside the InputBox

Detailed Steps to Decrypt Password

a) Let’s take an original password first (say – qwerty). When we encrypt this password using Password Encoder tool in QTP, we get 4e63eb23edd909f721d59eaa98fecb6d82a7 as the decrypted password (see below pic). Our aim is to use the decrypted password and obtain back the original password.
Encrypted String for Password – qwerty

b) Now the next step is to create an InputBox. To do this, write the following text in a notepad -
InputBox “The text box below displays the Decrypted Password”, “Decrypt Password”
Save the notepad as .vbs file in the local  disk (In this example, we are saving the notepad as ‘DecryptPwd.vbs’ in ‘D:’ drive). If we execute the ‘DecryptPwd.vbs’ file, it would display the InputBox as shown below.
InputBox to display the Decrypted (original) Password

c)  The final step is to use SetSecure method to display the original password in the InputBox. For this write the following code in QTP.
1
2
3
4
5


SystemUtil.Run “D:DecryptPwd.vbs”
 'Type the decrypted password in WinEdit field of InputBox
Dialog("nativeclass:=#32770","text:=Decrypt Password").WinEdit("nativeclass:=Edit").SetSecure "4e63eb23edd909f721d59eaa98fecb6d82a7"
When you execute this code, the InputBox gets opened and the SetSecure method enters the original decrypted password in the InputBox as displayed in the figure below. Now you can note down this decrypted password and use it wherever required.
The InputBox displays the original password – qwerty
Note: It is not necessary that the user uses VBScript InputBox to display the decrypted password. The logic can be written for any application where a text field is available.

How to Encrypt Passwords using QTP


his article covers the different aspects of password encryption in QTP. It talks about why password encryption may be needed, how to encrypt passwords using QTP and how to use the encrypted passwords in our scripts. Lets discuss all these points one by one.

Why Password Encryption is Needed?

In most of the automation projects, the scripts would be dealing with various user ids and passwords, be it application credentials, DB passwords and other similar things. And in many cases, the automation scripts would be maintained by multiple people/teams. In such situations, encrypted passwords can be used so that the original passwords are not exposed unnecessarily.

How to Encrypt Passwords in QTP

QTP provides the following two methods to encrypt passwords -

a) Using Password Encoder Utility: Password Encoder is a tool/utility provided by QTP to encode passwords. To encode any password using this tool -
i) Go to All Programs > HP QuickTest Professional > Tools > Password Encoder
ii) Enter the password to be encrypted in the Password field and click on Generate button. The encrypted password will be displayed in the ‘Encoded string’ field (as shown in the below figure).
Encrypted Password for ‘qwerty’

b) Using Crypt Object, Encrypt Method: Crypt is a QTP utility object which provides a method called Encrypt to encode strings. The below code shows how a password can be encoded using Encrypt method.
1
2
password = "qwerty"
msgbox Crypt.Encrypt(password)

How to use encrypted passwords in your scripts

QTP provides SetSecure method to set encrypted values in text fields. Unlike the normal Set method, which sets the plain text in a text field, SetSecure method decrypts the encrypted password first, and then sets the original decrypted value in a password field. Let’s see an example for this.
1
2
3
4
5
password = "qwerty"
sEncryptedPwd = Crypt.Encrypt(password) 'Enter Login Id & password
Browser("").Page("").WebEdit("userid").Set "user1"
Browser("").Page("").WebEdit("password").SetSecure sEncryptedPwd
In the above example, sEncryptedPwd variable contains the encrypted password. SetSecure method first decodes this password internally and then sets the decoded/decrypted password in the password field.

Note: SetSecure method decrypts a password only when it is in encrypted state. If we try to pass a plain (non encrypted) password to SetSecure method, then rather than decrypting the password, it just sets the same value in the text field.