使用 zxcvbn 设计插件来拒绝弱密码
Plugin for devise to reject weak passwords, using zxcvbn-rb which is a ruby port of zxcvbn: realistic password strength estimation.
The user's password will be rejected if the score is below 4 by default. It also uses the email as user input to zxcvbn, to reject passwords containing parts of the email (if using zxcvbn.js on the frontend you should also do this to get the same score).
The scores 0, 1, 2, 3 or 4 are given when the estimated crack time (seconds) is less than 10**2, 10**4, 10**6, 10**8, Infinity.
Add this line to your application's Gemfile:
gem 'devise_zxcvbn'…A score of less than 3 is not recommended.
# config/initializers/devise.rb
Devise.setup do |config|
config.min_password_score = 4
endThe default error message:
"not strong enough. It scored %{score}. It must score at least %{min_password_score}."You can customize this error message modifying the devise YAML file.
The crack_time_display, feedback, score and min_password_score variables are passed through if you need them.
# config/locales/devise.en.yml
en:
errors:
messages:
weak_password: "not strong enough. Consider adding a number, symbols or more letters to make it stronger."To turn off password complexity validation for certain conditions, you could implement a concern (or similar) that overloads skip_password_complexity?:
def skip_password_complexity?
true
endgit checkout -b my-new-feature)git commit -am 'Add some feature')git push origin my-new-feature)devise_zxcvbn is Copyright © 2013 Bit Zesty. It is free software, and may be redistributed under the terms specified in the LICENSE file.
devise_zxcvbn is maintained by Bit Zesty Limited. The names and logos for Bit Zesty are trademarks of Bit Zesty Limited.
See our other projects or hire us to design, develop, and support your product or service.
暂无开放 Issues,或尚未同步最近议题。