From 3a3993f2e12b34c97ca8b265daf8d389c06809d3 Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Wed, 11 Sep 2024 16:32:35 +0200 Subject: [PATCH] chore: attempt to inject our french dictionnary to new zxcvbn lib Co-Authored-By: Lisa Durand --- config/initializers/zxcvbn.rb | 9 +++++++++ config/words_fr_frequency_list.txt | 4 ++++ 2 files changed, 13 insertions(+) create mode 100644 config/initializers/zxcvbn.rb create mode 100644 config/words_fr_frequency_list.txt diff --git a/config/initializers/zxcvbn.rb b/config/initializers/zxcvbn.rb new file mode 100644 index 000000000..bf725f993 --- /dev/null +++ b/config/initializers/zxcvbn.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +path = Rails.root.join("config/words_fr_frequency_list.txt") +lines = path.readlines.map(&:strip) +filename = File.basename(path, ".*") + +new_ranked_dictionary = Hash[filename, Zxcvbn::Matching.build_ranked_dict(lines)] +# Zxcvbn::Matching::RANKED_DICTIONARIES.merge! new_ranked_dictionary +Zxcvbn::Matching::RANKED_DICTIONARIES = new_ranked_dictionary diff --git a/config/words_fr_frequency_list.txt b/config/words_fr_frequency_list.txt new file mode 100644 index 000000000..fa53d2086 --- /dev/null +++ b/config/words_fr_frequency_list.txt @@ -0,0 +1,4 @@ +password +00000000 +test +azerty