No commit activity in last 3 years
No release in over 3 years
An activeModel Validator that provides a quick and easy way to validate a password against a user defined schema
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 4.0.0
>= 1.0.0
~> 2.3
 Project Readme

CircleCI

password_schema_validator

Password Schema Validator is an extension for Active Model Validations that provides an easy way to validate a password or a string against a user defined schema. This gem is a motivation from the npm module - https://github.com/tarunbatra/password-validator

Install

gem 'password_schema_validator', '~> 1.0'

Usage

Password Schema Validator needs to be used like a usual Rails model validation. Suppose, a field named 'password' is to be validated. For this, a schema needs to be defined with the options available in the 'password_schema_validator' and this schema should to be passed to the 'with_schema' validator.

class User
    validates :name, presence: true
    validates :password, with_schema: {
        min_len: 5,
        max_len: 10,
        digits: true
    }
end

and now, one can use this as .........

user = User.new(name: "duke_nukem", password: "pass")
user.valid? # false
user.errors.messages # { :password => ["must be minimum 5 character long", "must contain digits"] }

user = User.new(name: "duke_nukem", password: "$pass123")
user.valid? # true

Validation Options

Option key Value datatype Description
min_len integer validates if the password has at least "min_len" characters.
max_len integer validates if the password has not more than "max_len" characters.
lower_case boolean validates if the password has at least one lower case character.
upper_case boolean validates if the password has at least one upper case character.
letters boolean validates if the password has at least one letter [a-z, A-Z].
digits boolean validates if the password has at least one numerical character.
special_charater boolean validates if the password has at least one special character.
discarded_words array validates if the password if not one among the discarded word list.

ToDo

  • Add option to support a dictionary of weak passwords to prevent user from choosing some weak passwords like "password" or "password123".
  • Add option to support explicitely specify allowed special characters in the options.
  • Documentation via Rdoc.

Contributing

Pull Requests and Bug Fixes are most welcome.

  • Fork the Project.
  • Run bundle.
  • Make your feature branch or Bug-Fix.
  • Add tests for it. This is important so that it doesn't break future versions unintentionally.
  • Commit the changes without messing with the history or version.
  • Create Pull request.