nobspw 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 50bde3af21d4ae1a914fdf29d97c7cd4636f9045d12053b19b03b10562432200
4
- data.tar.gz: bb15b53c7660e771fd4d0d430be1882186d11515662d1ffe9f221478f4df0013
3
+ metadata.gz: a69bacd3f3f32acf44341c98cc21d7680a46638d6404b62e51ebe1ec09170a26
4
+ data.tar.gz: 84cf94ef83bad08505f3563f54fe3f1cebb8b87ef7583f26a47e525b2d6a2baf
5
5
  SHA512:
6
- metadata.gz: f8688c43975ea97d01f0bb39d8213dd221f7e4ec1022cba7b068e079c7e6213a826dc36949b90582ca2e3e8a23b9f7e9388904357c2166deaf5ef614ea646f83
7
- data.tar.gz: 1c2f2a8835ab93d53bcb187bc7eb86123280d2c831114a7c5f26822708ee44ac1d20ac41c797a8a9b0d57543a44a0de3c3bcb1104a6f4cbea2c8c4033e9db871
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
- "#{NOBSPW.configuration.grep_path} '^#{@password}$' #{path}"
42
+ escaped_pw = Shellwords.escape(@password)
43
+ "#{NOBSPW.configuration.grep_path} '^#{escaped_pw}$' #{path}"
41
44
  end
42
45
  end
43
46
  end
@@ -1,3 +1,3 @@
1
1
  module NOBSPW
2
- VERSION = '0.5.0'
2
+ VERSION = '0.5.1'
3
3
  end
@@ -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.0
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: