diff --git a/CHANGELOG.md b/CHANGELOG.md index 871fdaa..76d6661 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## New version * We don't need to add `config.action_mailer.default_url_options` anymore +* Make gem add bcrypt more resilient ## Authentication Zero 4.0.2 ## diff --git a/lib/generators/authentication/authentication_generator.rb b/lib/generators/authentication/authentication_generator.rb index 1cf4667..ad0b807 100644 --- a/lib/generators/authentication/authentication_generator.rb +++ b/lib/generators/authentication/authentication_generator.rb @@ -19,7 +19,11 @@ class AuthenticationGenerator < Rails::Generators::Base source_root File.expand_path("templates", __dir__) def add_gems - gem "bcrypt", "~> 3.1.7", comment: "Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]" + if bcrypt_present? + uncomment_lines "Gemfile", /gem "bcrypt"/ + else + gem "bcrypt", "~> 3.1.7", comment: "Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]" + end if options.pwned? gem "pwned", comment: "Use Pwned to check if a password has been found in any of the huge data breaches [https://github.com/philnash/pwned]" @@ -241,6 +245,10 @@ def sudoable? options.sudoable? && !options.api? end + def bcrypt_present? + File.read("Gemfile").include?('gem "bcrypt"') + end + def importmaps? Rails.root.join("config/importmap.rb").exist? end