password_strength_validator 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +45 -0
- data/Rakefile +11 -0
- data/bin/console +7 -0
- data/lib/active_model/validations/password_strength_validator.rb +10 -0
- data/lib/password_strength_validator.rb +3 -0
- data/lib/password_strength_validator/validator.rb +50 -0
- data/lib/password_strength_validator/version.rb +3 -0
- data/password_strength_validator.gemspec +27 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 40eb0c731f91de78bfe7f44b770137c7ab2c7c95
|
4
|
+
data.tar.gz: 95ed2b573cc9dc5dce2c2772bc055ceb89165d3b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4844e6bb822b8939ad88d8fc8b32eeda131acbaecf7fdaa8750e90796c4320a613943d1b67c4df0a4065346151f9cb7e9d8ae5ea3c03ba63d59e0a893b0b4a9b
|
7
|
+
data.tar.gz: 0fa0fa82cacef99298923587bf28c4f0e4476206adbe58c2127e057ebe4228c099866efcf6e0d2755218df5035e5291c6b68a8b0761409f14627af0fcb093180
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 SHIOYA, Hiromu
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# PasswordStrengthValidator
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/kwappa/password_strength_validator.svg?branch=master)](https://travis-ci.org/kwappa/password_strength_validator)
|
4
|
+
|
5
|
+
validates strength of password with ActiveRecord
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
- with default options
|
10
|
+
- require 8 - 72 characters
|
11
|
+
- require both uppercase and lowercase
|
12
|
+
- require 1 or more digtis
|
13
|
+
|
14
|
+
```
|
15
|
+
class TestModel < ActiveRecord::Base
|
16
|
+
validates :password, password_strength: true
|
17
|
+
end
|
18
|
+
```
|
19
|
+
|
20
|
+
- add extra option for more strength
|
21
|
+
- rquire 12 - 72 characters
|
22
|
+
- require 3 or more digits
|
23
|
+
- require 3 or more symbols
|
24
|
+
|
25
|
+
```
|
26
|
+
class StrongTestModel < ActiveRecord::Base
|
27
|
+
validates :password, password_strength: { min_length: 12, number_of_digits: 3, number_of_symbols: 3 }
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
- acceptable symbols:
|
32
|
+
|
33
|
+
```
|
34
|
+
!"\#$%&'()*+,-./:;<=>?[\]^_`{|}~
|
35
|
+
```
|
36
|
+
|
37
|
+
- custom error message
|
38
|
+
|
39
|
+
to cusotomize error message, specify your local file with key:
|
40
|
+
|
41
|
+
`#{lang}.errors.messages.weak_password`
|
42
|
+
|
43
|
+
## License
|
44
|
+
|
45
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
module ActiveModel::Validations
|
2
|
+
class PasswordStrengthValidator < ActiveModel::EachValidator
|
3
|
+
def validate_each(record, attribute, value)
|
4
|
+
validator = ::PasswordStrengthValidator::Validator.new(value, self.options)
|
5
|
+
unless validator.valid?
|
6
|
+
record.errors.add(attribute, :weak_password)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
3
|
+
module PasswordStrengthValidator
|
4
|
+
DEFAULT_OPTIONS = {
|
5
|
+
min_length: 8,
|
6
|
+
max_length: 72,
|
7
|
+
require_uppercase: true,
|
8
|
+
require_lowercase: true,
|
9
|
+
number_of_digits: 1,
|
10
|
+
number_of_symbols: 0,
|
11
|
+
}.freeze
|
12
|
+
|
13
|
+
SYMBOLS = [
|
14
|
+
33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
|
15
|
+
58, 59, 60, 61, 62, 63, 64,
|
16
|
+
91, 92, 93, 94, 95, 96,
|
17
|
+
123, 124, 125, 126
|
18
|
+
].freeze
|
19
|
+
|
20
|
+
class Validator
|
21
|
+
def initialize(password, options = {})
|
22
|
+
@password = password
|
23
|
+
@options = OpenStruct.new(DEFAULT_OPTIONS.merge(options))
|
24
|
+
end
|
25
|
+
|
26
|
+
def valid?
|
27
|
+
enough_length? && has_uppercase? && has_lowercase? && has_enough_digits? && has_enough_symbols?
|
28
|
+
end
|
29
|
+
|
30
|
+
def enough_length?
|
31
|
+
@password.length.between?(@options.min_length, @options.max_length)
|
32
|
+
end
|
33
|
+
|
34
|
+
def has_uppercase?
|
35
|
+
!@options.require_uppercase || !!@password.match(/[A-Z]/)
|
36
|
+
end
|
37
|
+
|
38
|
+
def has_lowercase?
|
39
|
+
!@options.require_lowercase || !!@password.match(/[a-z]/)
|
40
|
+
end
|
41
|
+
|
42
|
+
def has_enough_digits?
|
43
|
+
@password.split('').find_all { |c| c.match(/[0-9]/) }.size >= @options.number_of_digits
|
44
|
+
end
|
45
|
+
|
46
|
+
def has_enough_symbols?
|
47
|
+
@password.split('').map { |c| c.unpack('*C') }.flatten.find_all { |cc| SYMBOLS.include?(cc) }.size >= @options.number_of_symbols
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'password_strength_validator/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'password_strength_validator'
|
7
|
+
spec.version = PasswordStrengthValidator::VERSION
|
8
|
+
spec.authors = ['SHIOYA, Hiromu']
|
9
|
+
spec.email = ['kwappa.856@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = 'validates strength of password with ActiveRecord'
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = 'https://github.com/kwappa/password_strength_validator'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = 'exe'
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_dependency "activemodel"
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler'
|
24
|
+
spec.add_development_dependency 'rake'
|
25
|
+
spec.add_development_dependency 'rspec'
|
26
|
+
spec.add_development_dependency 'pry'
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: password_strength_validator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- SHIOYA, Hiromu
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activemodel
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: validates strength of password with ActiveRecord
|
84
|
+
email:
|
85
|
+
- kwappa.856@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".travis.yml"
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- bin/console
|
97
|
+
- lib/active_model/validations/password_strength_validator.rb
|
98
|
+
- lib/password_strength_validator.rb
|
99
|
+
- lib/password_strength_validator/validator.rb
|
100
|
+
- lib/password_strength_validator/version.rb
|
101
|
+
- password_strength_validator.gemspec
|
102
|
+
homepage: https://github.com/kwappa/password_strength_validator
|
103
|
+
licenses:
|
104
|
+
- MIT
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.5.2
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: validates strength of password with ActiveRecord
|
126
|
+
test_files: []
|