8000 Provide a simple validator · Issue #2 · k3integrations/hibp_check · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Provide a simple validator #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you 8000 agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
TylerRick opened this issue Jan 31, 2019 · 1 comment
Open

Provide a simple validator #2

TylerRick opened this issue Jan 31, 2019 · 1 comment

Comments

@TylerRick
Copy link
TylerRick commented Jan 31, 2019

Provide a validator so you can simply add something like this to your model:

validates :password, not_pwned: true

or

validates :password, not_breached: true

Maybe something like this...

  validates_each :password, allow_blank: true do |user, attr, value|
    HibpCheck.new.password_used_count(value).tap do |count|
      user.errors.add attr, :breached_with_count, count: count
    end
  end

Maybe allow the HibpCheck instance to be specified in a config somewhere so users can configure it if needed.

Would it be at all useful to be able to specify a minimum number of breaches needed to trigger the validation error or is minimum: 1 always what users will want?

Maybe provide a default en.yml locale file in the Railtie so it works out of the box? (That's what I did with https://github.com/TylerRick/activemodel-validators/blob/master/config/locales/en.yml anyway.) I think users can still easily override in their app's en.yml file...

@TylerRick
Copy link
Author

I've come across some other libraries that have Rails/validator integration built-in, such as:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant
0