demarches-normaliennes/app/services/zxcvbn_service.rb
2024-09-18 12:57:58 +02:00

18 lines
525 B
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# frozen_string_literal: true
class ZxcvbnService
@tester_mutex = Mutex.new
# 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
def self.complexity(password)= tester.test(password.to_s).score
end