nobspw 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/nobspw/password_checker.rb +4 -1
- data/lib/nobspw/version.rb +1 -1
- data/misc/grep_benchmark.rb +23 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a69bacd3f3f32acf44341c98cc21d7680a46638d6404b62e51ebe1ec09170a26
|
4
|
+
data.tar.gz: 84cf94ef83bad08505f3563f54fe3f1cebb8b87ef7583f26a47e525b2d6a2baf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3b89294eb061d12bbce3d2e69554598993c84e61fd54e352a16cbaaf298df86d3755e05ab2acaa52d19525f4580d72db947dacbc34cbb17f3e215a8bd8f560b
|
7
|
+
data.tar.gz: 9c5d5c21fcf1dbdbbab22081e0cd263d5acd0949dc32216c5d2aae3d60e6aea65f0b16729b29ad4011d49ad7cb9a693c76deb70cbb4cefce7fd897da0774ed6e
|
data/README.md
CHANGED
@@ -70,7 +70,7 @@ Optionally, you can configure some options:
|
|
70
70
|
I included `PasswordValidator` for Rails. Validating passwords in your model couldn't be easier:
|
71
71
|
|
72
72
|
```ruby
|
73
|
-
validates :password, presence: true, password: true, if: -> { new_record? || changes[:password] }
|
73
|
+
validates :password, presence: true, password: true, if: -> { new_record? || changes[:password] || changes[:password_digest] }
|
74
74
|
```
|
75
75
|
|
76
76
|
PasswordValidator will try to guess the correct field name for each `PasswordChecker` argument as follow:
|
@@ -84,7 +84,7 @@ If you have field names different than above, you can tell `PasswordValidator` w
|
|
84
84
|
```ruby
|
85
85
|
validates :password, password: { :name => :customer_name,
|
86
86
|
:email => :electronic_address },
|
87
|
-
if: -> { new_record? || changes[:password] }
|
87
|
+
if: -> { new_record? || changes[:password] || changes[:password_digest] }
|
88
88
|
```
|
89
89
|
|
90
90
|
## Validations
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'shellwords'
|
2
|
+
|
1
3
|
module NOBSPW
|
2
4
|
class PasswordChecker
|
3
5
|
include NOBSPW::ValidationMethods
|
@@ -37,7 +39,8 @@ module NOBSPW
|
|
37
39
|
end
|
38
40
|
|
39
41
|
def grep_command(path)
|
40
|
-
|
42
|
+
escaped_pw = Shellwords.escape(@password)
|
43
|
+
"#{NOBSPW.configuration.grep_path} '^#{escaped_pw}$' #{path}"
|
41
44
|
end
|
42
45
|
end
|
43
46
|
end
|
data/lib/nobspw/version.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'benchmark'
|
4
|
+
require 'shellwords'
|
5
|
+
|
6
|
+
password = 'swordfish'
|
7
|
+
dictionary_path = File.join(File.dirname(__FILE__), '..', 'lib/db/dictionary.txt')
|
8
|
+
|
9
|
+
def shell_grep(password, dictionary)
|
10
|
+
password = Shellwords.escape(password)
|
11
|
+
"/usr/bin/grep '^#{password}$' #{dictionary}"
|
12
|
+
$?.exitstatus == 0
|
13
|
+
end
|
14
|
+
|
15
|
+
Benchmark.bm do |benchmark|
|
16
|
+
benchmark.report("Ruby") do
|
17
|
+
25.times { File.open(dictionary_path).grep(/^#{password}$/) }
|
18
|
+
end
|
19
|
+
|
20
|
+
benchmark.report("Shell") do
|
21
|
+
25.times { shell_grep(password, dictionary_path) }
|
22
|
+
end
|
23
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nobspw
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carl Mercier
|
@@ -189,6 +189,7 @@ files:
|
|
189
189
|
- lib/nobspw/password_checker.rb
|
190
190
|
- lib/nobspw/validation_methods.rb
|
191
191
|
- lib/nobspw/version.rb
|
192
|
+
- misc/grep_benchmark.rb
|
192
193
|
- nobspw.gemspec
|
193
194
|
homepage: https://github.com/cmer/nobspw
|
194
195
|
licenses:
|