demarches-normaliennes/app/services/zxcvbn_service.rb

19 lines
525 B
Ruby
Raw Normal View History

# frozen_string_literal: true
class ZxcvbnService
@tester_mutex = Mutex.new
2024-09-17 10:59:58 +02:00
# Returns an Zxcvbn instance cached between classes instances and between threads.
#
# The tester weights ~20 Mo, and we'd like to save some memory so rather
# that storing it in a per-thread accessor, we prefer to use a mutex
# to cache it between threads.
def self.tester
@tester_mutex.synchronize do
@tester ||= Zxcvbn::Tester.new
end
end
2024-09-17 10:59:58 +02:00
def self.complexity(password)= tester.test(password.to_s).score
end