I have huge number of passwords, it difficult to encrypt password one by one from LR's Password Encoder. What is the way forward on this.
Cybersecurity
DevOps Cloud
IT Operations Cloud
If an answer to your question is correct, click on "Verify Answer" under the "More" button. The answer will now appear with a checkmark. Please be sure to always mark answers that resolve your issue as verified. Your fellow Community members will appreciate it!  Learn more
I have huge number of passwords, it difficult to encrypt password one by one from LR's Password Encoder. What is the way forward on this.
To encrypt password in LRE, We can make use of PasswordEncoderConsole.exe which is available in VuGen's installation\bin directory.
It accepts a password on command line and output result to console.
I have created a simple PowerShell script which will take the inputs from file and encrypt them into a new file.
Below is the code. Copy this code into a file and save it as “password_encode.ps1” and run.
Note:- Change the source file and output file as per your location.
$sourceFile = "C:\Users\admin\Downloads\test.txt" $outputFile = "C:\Users\admin\Downloads\testEncrypted.txt" Clear-Content -Path $outputFile Write-Output "Encrypting passwords" foreach($line in Get-Content $sourceFile) { & "C:\Program Files (x86)\Micro Focus\Virtual User Generator\bin\PasswordEncoderConsole.exe" $line | Out-File -FilePath $outputFile -Append }
Venkatesan Arjunan I have a similar scenario, can you please assist?
Your above script takes the input from txt file and encrypt it using password encode.exe and write to testEncrypted.txt file. Instead input will be retrieved from web_reg_save_param function say password_param. Now password_param should be taken as input to powershell script and write to a textEncrypted.txt. How can this be achieved? Appreciate your response.
I don't know why you wanted to do this way but you can try two things.
Action() { const char *executablePath = "\"C:\\Program Files (x86)\\Micro Focus\\Virtual User Generator\\bin\\PasswordEncoderConsole.exe\""; char command[300], buf[1024], encryptedPwd[1024], trimmed_out[1024]; long fp; // const char *arguments= "password"; lr_save_string("password123", "param_password"); snprintf(command, sizeof(command), "%s %s", executablePath , lr_eval_string("{param_password}")); lr_output_message(command); fp = popen(command, "r"); while (fgets(buf, sizeof(buf), fp) != 0) { remove_newline(buf, trimmed_out); lr_save_string(buf, "encryptedPwdWithoutTrim"); lr_save_string(trimmed_out, "encryptedPwdTrimmed"); } pclose(fp); lr_output_message("decyptedPwd %s", lr_unmask(lr_eval_string("{encryptedPwdTrimmed}"))); return 0; } void remove_newline(const char *source, char *destination) { while (*source) { if (*source != '\n') { *destination = *source; destination++; } source++; } *destination = '\0'; }
output for the above code is below. I had to trim the output of PasswordEncoderConsole.exe as it produces newline as well.
Virtual User Script started at: 22/05/2024 10:52:24 Starting action vuser_init. Web Turbo Replay of LoadRunner 2023.0.0 for Windows 10; build 506 (Mar 08 2023 13:11:40) [MsgId: MMSG-26983] Run mode: HTML [MsgId: MMSG-26993] Replay user agent: Go-http-client/1.1 [MsgId: MMSG-26988] Runtime Settings file: "C:\Venkat\LR_Scripts\Common\password_encoding_using_vugen\\default.cfg" [MsgId: MMSG-27141] Ending action vuser_init. Running Vuser... Starting iteration 1. Maximum number of concurrent connections per server: 2 [MsgId: MMSG-26989] Starting action Action. Action.c(9): Notify: Saving Parameter "param_password = password123". Action.c(11): Notify: Parameter Substitution: parameter "param_password" = "password123" Action.c(13): "C:\Program Files (x86)\Micro Focus\Virtual User Generator\bin\PasswordEncoderConsole.exe" password123 Action.c(19): Notify: Saving Parameter "encryptedPwdWithoutTrim = 664dc05a165e47506b32f69142cce4\n". Action.c(20): Notify: Saving Parameter "encryptedPwdTrimmed = 664dc05a165e47506b32f69142cce4". Action.c(24): Notify: Parameter Substitution: parameter "encryptedPwdTrimmed" = "664dc05a165e47506b32f69142cce4" Action.c(24): decyptedPwd password123 Ending action Action. Ending iteration 1. Ending Vuser... Starting action vuser_end. Ending action vuser_end. Vuser Terminated.
Thank you so much Venkatesan Arjunan This is exactly what I'm looking for. Also, since our password is too long, script running for 1 iteration is taking long time to complete as it goes to while loop to remove extra line generated by password encoder. If we can remove that step from script and write encrypted password with "\n", I can fix it by using notepad to remove \n piece. I would really appreciate if you can modify the script to write encrypted password with \n so that it saves script run time for several 1000 passwords.
if you want to write the encrypted password directly to a file, then the script will become very simple. See the below updated script for you. There is no need to remove "/n" as it will be written as new line on text file.
The encrypted passwords will be written to a file called "encrypted_pwd.txt" on your script folder. There is no
Action() { long FileVarriable; char FileLocation[1024] = "encrypted_pwd.txt"; const char *executablePath = "\"C:\\Program Files (x86)\\Micro Focus\\Virtual User Generator\\bin\\PasswordEncoderConsole.exe\""; char command[300], buf[1024], encryptedPwd[1024]; long fp; // const char *arguments= "password"; lr_save_string("password123", "param_password"); snprintf(command, sizeof(command), "%s %s", executablePath , lr_eval_string("{param_password}")); fp = popen(command, "r"); while (fgets(buf, sizeof(buf), fp) != 0) { lr_save_string(buf, "encryptedPwd"); } pclose(fp); FileVarriable = fopen (FileLocation,"a+"); fprintf (FileVarriable, "%s", lr_eval_string("{encryptedPwd}")); fclose (FileVarriable); return 0; }