Skip to content

Commit d0b3227

Browse files
committed
Make gem add bcrypt more resilient
1 parent bfc80b5 commit d0b3227

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## New version
22

33
* We don't need to add `config.action_mailer.default_url_options` anymore
4+
* Make gem add bcrypt more resilient
45

56
## Authentication Zero 4.0.2 ##
67

lib/generators/authentication/authentication_generator.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ class AuthenticationGenerator < Rails::Generators::Base
1919
source_root File.expand_path("templates", __dir__)
2020

2121
def add_gems
22-
gem "bcrypt", "~> 3.1.7", comment: "Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]"
22+
if bcrypt_present?
23+
uncomment_lines "Gemfile", /gem "bcrypt"/
24+
else
25+
gem "bcrypt", "~> 3.1.7", comment: "Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]"
26+
end
2327

2428
if options.pwned?
2529
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?
241245
options.sudoable? && !options.api?
242246
end
243247

248+
def bcrypt_present?
249+
File.read("Gemfile").include?('gem "bcrypt"')
250+
end
251+
244252
def importmaps?
245253
Rails.root.join("config/importmap.rb").exist?
246254
end

0 commit comments

Comments
 (0)