site
stats
By Anish Pillai Anish Pillai Posted under QTP Basic Stuff

How to Encrypt Passwords using QTP

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×

This 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.

Encrypt Password using QTP

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.

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.

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.

You can also read: How to obtain the decrypted value of an encrypted password

If you enjoyed this article, you can join our blog to get new articles delivered directly in your inbox.

You can also visit Automation Repository Home Page or the Archives Page to view the other articles.

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×
  • jenny

    where to find "Encoded string"

    • Anish10110

      Jenny, the encoded string will be available in the 'Password Encoder' dialog box. Once we provide the original password and click on Generate button, the tool will generate the encoded string for you.

  • Meir Bar-Tal

    I published a solution to decrypt encrypted passwords automatically with QTP.
    You can see it at <a href="http://preview.tinyurl.com/95kk9t9&quot; target="_blank">http://preview.tinyurl.com/95kk9t9</a&gt;

  • Joseph Varghese

    this is not secure at all, I can use the setsecure method on a textfield and pass the encrypted string and read the password.

  • vilas

    hi

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×