Rahul
Rahul

Reputation: 37

How to use password hashing using BCrypt in Jmeter

I have to use bCrypt hash generator for encrypting any string.

Steps I have taken: #

1- Added Jar file in Lib folder
2- Restarted the Jmeter
3- Added below code in JSR223 Sampler

String password = "1234"; 
String bcryptHashString = BCrypt.withDefaults().hashToString(10, password.toCharArray());

2023-10-06 13:27:53,749 ERROR o.a.j.p.j.s.JSR223Sampler: Problem in JSR223 script JSR223 Sampler, message: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: BCrypt for class: Script228 javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: BCrypt for class: Script228 at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:320) ~[groovy-jsr223-3.0.5.jar:3.0.5] at org.codehaus.groovy.jsr223.GroovyCompiledScript.eval(GroovyCompiledScript.java:71) ~[groovy-jsr223-3.0.5.jar:3.0.5] at javax.script.CompiledScript.eval(Unknown Source) ~[?:1.8.0_381] at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:217) ~[ApacheJMeter_core.jar:5.4.1] at org.apache.jmeter.protocol.java.sampler.JSR223Sampler.sample(JSR223Sampler.java:72) [ApacheJMeter_java.jar:5.4.1] at org.apache.jmeter.threads.JMeterThread.doSampling(JMeterThread.java:638) [ApacheJMeter_core.jar:5.4.1] at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:558) [ApacheJMeter_core.jar:5.4.1] at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:489) [ApacheJMeter_core.jar:5.4.1] at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:256) [ApacheJMeter_core.jar:5.4.1]

Upvotes: 0

Views: 210

Answers (1)

Dmitri T
Dmitri T

Reputation: 168157

I think you forgot to copy and paste the necessary import statement

import at.favre.lib.crypto.bcrypt.BCrypt

enter image description here

also you need to add files, not the file, bcrypt won't work without bytes utility library

More information on Groovy scripting in JMeter: Apache Groovy: What Is Groovy Used For?

Upvotes: 0

Related Questions