Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Resurrecting this old issue because I believe the current answers are wrong and this thread pops high in google searches.</p> <p>Looked at the code and ran a couple of simple tests. jbcryt appears to be thread safe.</p> <p>In the code: -although it has mostly static method, those methods create instances of the bcrypt class to do computations when needed.</p> <p>Test samples: -had bcrypt not been thread safe, I would have expected either of these methods to throw some form of error, which they did not.</p> <pre><code>@Test public void multiThreadHash() throws InterruptedException{ List&lt;Thread&gt; threads = new ArrayList&lt;Thread&gt;(); for(int i = 0; i&lt;40; i++){ threads.add(new Thread(){ @Override public void run() { long start = System.currentTimeMillis(); while(System.currentTimeMillis()&lt;start+12000){ String password = "sample"; String hash = BCrypt.gensalt(4); String hashed = BCrypt.hashpw(password, hash); } } }); } for(Thread t: threads){ t.start(); } Thread.sleep(12200L); } @Test public void multiThreadReproductibleHash() throws InterruptedException{ List&lt;Thread&gt; threads = new ArrayList&lt;Thread&gt;(); for(int i = 0; i&lt;40; i++){ threads.add(new Thread(){ @Override public void run() { long start = System.currentTimeMillis(); while(System.currentTimeMillis()&lt;start+12000){ String password = "sample"; String hash = "$2a$04$/YkrS2ifyAloNVUk5qAO7O"; String expected = "$2a$04$/YkrS2ifyAloNVUk5qAO7OlqIsp2ECTMDinOij9wvn7nXPRJCo8Gy"; String hashed = BCrypt.hashpw(password, hash); Assert.assertEquals(expected, hashed); } } }); } for(Thread t: threads){ t.start(); } Thread.sleep(12200L); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload