smpallen99/coherence

**Feature Request** Give option to make bcrypt 0 pass in test or dev environment for speed gains.

iantbutler01 opened this issue · 2 comments

Basically, in the event of seeding a database or other testing, it would be nice to have an option to either bypass the bcrypt encryption or make it 0 pass for essentially the same effect.

There are significant slowdowns that occur with the encryption which in a production setting is simply the tradeoff you make for security but under testing conditions where people may need to seed 1000s of users, there should be a way to configure the encryption to speed up that creation.

Below are two benchmarks the first is after I patched out the call to bcrypt and returned the plain password in schema.ex and then recompiled, the latter is with encryption on.

*** &UserFactory.create_user/1 ***
1.3 sec 16K iterations 84.19 μs/op

*** &UserFactory.create_user/1 ***
2.1 sec 7 iterations 311046.72 μs/op

This all started here, where I am the OP
https://www.reddit.com/r/elixir/comments/8n5mdh/code_very_slow_what_am_i_missing/

It took 5 minutes to seed 1000 users which was insane to me, less so after realizing where password encryption was being handled but I think faster configuration for the encryption that in a test environment is somewhat standard of a practice for this.

Let me know what you think. I would be happy to implement this and supply a PR if it is something that people want.

The workaround I just finished was adding comeonin 3.0 to my deps along with bcrypt_elixir and setting comeonin's hashing config in my test.exs/dev.exs but I think there should be a direct route from coherence to handle that config without having to do that.

Excellent idea. I'd love to see a PR.