Password Encryption while entering during run time. - nyObject - 03-22-2011
'=============================================
'Action Name : To Login
'=============================================
Code: 'Initiaze the String variables
Dim InpUserName, InpPass, PassString
' To Enter Network ID while running
InpUserName = InputBox ("Enter Username", "User Input")
Browser("micclass:=Browser").Page("micClass:Page").WebEdit("userid").Set InpUserName
'To enter Network ID Password
InpPass = InputBox ("Enter Password")
PassString = Crypt.Encrypt(InpPass)
Browser("micclass:=Browser").Page("micClass:Page").WebEdit("pwd").SetSecure PassString
Browser("micclass:=Browser").Page("micClass:Page").WebButton("Sign In").Click
--------------------------------------------------------------
Question: As we change the n/w password quiet frequently, I have used this method to login while running the script. But Even after trying lot of times I couldnt find a way to encrypt the password while runnig the script, Like Gmail password with asteriks (****). Anyone Please advise.
RE: Password Encryption while entering during run time. - basanth27 - 03-22-2011
Which part are you desiring for the asteriks to come up ?
1. On the Password InputBox?
2. On the application?
RE: Password Encryption while entering during run time. - cdesserich - 03-23-2011
The best way I know how is to use .NET components. These functions can be added to a function library or just included in the test you are running.
Code: Public Function EncryptedPassword()
Dim dialogForm, dialogTextBox, dialogAcceptButton, dialogStartPosition, dialogBorderStyle, ResultEnum
Set dialogForm = DotNetFactory.CreateInstance("System.Windows.Forms.Form", "System.Windows.Forms")
Set dialogTextBox = DotNetFactory.CreateInstance("System.Windows.Forms.TextBox", "System.Windows.Forms")
Set dialogAcceptButton = DotNetFactory.CreateInstance("System.Windows.Forms.Button", "System.Windows.Forms")
Set dialogStartPosition = DotNetFactory.CreateInstance("System.Windows.Forms.FormStartPosition", "System.Windows.Forms")
Set dialogBorderStyle = DotNetFactory.CreateInstance("System.Windows.Forms.FormBorderStyle", "System.Windows.Forms")
Set ResultEnum = DotNetFactory.CreateInstance("System.Windows.Forms.DialogResult", "System.Windows.Forms")
dialogForm.Text = "Enter Password"
dialogForm.Width = 250
dialogForm.Height = 100
dialogForm.MinimizeBox = False
dialogForm.MaximizeBox = False
dialogForm.StartPosition = dialogStartPosition.CenterScreen
dialogForm.FormBorderStyle = dialogBorderStyle.FixedDialog
dialogTextBox.UseSystemPasswordChar = True
dialogTextBox.Width = 220
dialogTextBox.Top = 15
dialogTextBox.Left = 15
dialogAcceptButton.Text = "OK"
dialogAcceptButton.Top = 45
dialogAcceptButton.Left = 90
dialogForm.AcceptButton = dialogAcceptButton
dialogForm.AcceptButton.DialogResult = ResultEnum.OK
dialogForm.Controls.Add dialogTextBox
dialogForm.Controls.Add dialogAcceptButton
Do
dialogForm.ShowDialog(GetQtpNativeWindow)
dialogForm.Text = "Enter Password - CANNOT BE BLANK"
Loop While dialogTextBox.Text = ""
EncryptedPassword = Crypt.Encrypt(dialogTextBox.Text)
'MsgBox dialogTextBox.Text
dialogAcceptButton.Dispose
dialogTextBox.Dispose
dialogForm.Dispose
Set dialogBorderStyle = Nothing
Set dialogStartPosition = Nothing
Set dialogAcceptButton = Nothing
Set dialogTextBox = Nothing
Set dialogForm = Nothing
End Function
Private Function GetQtpNativeWindow
Dim hWnd, qtpWnd
Set hWnd = DotNetFactory.CreateInstance("System.IntPtr", "Mscorlib", Window("RegExpWndTitle:=QuickTest Professional.*").GetROProperty("hWnd"))
Set qtpWnd = DotNetFactory.CreateInstance("System.Windows.Forms.NativeWindow", "System.Windows.Forms")
qtpWnd.AssignHandle hWnd
Set GetQtpNativeWindow = qtpWnd
Set hWnd = Nothing
Set qtpWnd = Nothing
End Function
Then to use it with your code, you simply call the EncryptedPassword function for your SetSecure call. It will prompt with a password masked box.
Code: Browser("micclass:=Browser").Page("micClass:Page").WebEdit("pwd").SetSecure EncryptedPassword
EDIT: I should point out that those functions really shouldn't be included in the test itself, they will run MUCH faster if included in a function library.
|