validates_password_strength 0.0.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e379cf03a22ed639fd43e38acbfa6e86eb355b02
4
- data.tar.gz: 81b816a221bbda427a21a63eb1a27260a2f0283c
3
+ metadata.gz: e6864568e5716e4871b187fd0035db23df6675e5
4
+ data.tar.gz: 7f5510f0fc9ef26d2b3e480985102c43d60fd76b
5
5
  SHA512:
6
- metadata.gz: 41790af0caf6118ebffc9c593cdb347549013d8e577e1914db3a08e737cdfdacbca7673fb41224b9b5d09072cc3b846ab2ec59178736d5f206e2e7d58d9b4725
7
- data.tar.gz: 383ac2ff128e6e360150c9395b65ed4aa8d0e9f58434c6e35adf96401bb5019e6677f347aa6dedae46184279d61fe1c473b651dfbfe94c50aa167ba0cfc4bd3d
6
+ metadata.gz: c8bf6d80122c7afe3a6a76f99d744a98dfb60c7d3ffe066e7d70c2957a0f5cea16bdae06e3cb33c7fd63c6ec4d44309410ac9b995a33105de050d1470ac856ce
7
+ data.tar.gz: fe50d86c2c8cfa2b39d9bef7ace21882762893160a97db39d4096994d5c1e3c01fdfdb658bc88b4f640a337a10991b7e56c9fa660c3b5c27fe79f3d8302634f3
data/Gemfile CHANGED
@@ -8,4 +8,4 @@ gem 'pry'
8
8
  gem 'jasmine'
9
9
  gem 'guard'
10
10
  gem 'coffee-script'
11
- gem 'guard-sprockets', github: 'sandrew/guard-sprockets'
11
+ gem 'guard-sprockets'
data/Guardfile CHANGED
@@ -1,7 +1,8 @@
1
+ require 'validates_password_strength'
1
2
  require 'coffee_script'
2
3
  require 'erb'
3
4
 
4
5
  guard 'sprockets', destination: 'tmp/js', :asset_paths => ['app/assets/javascripts', 'spec/javascripts'] do
5
- watch 'app/assets/javascripts/validates_password_strength.js.coffee'
6
+ watch 'app/assets/javascripts/validates_password_strength.js.coffee.erb'
6
7
  watch 'spec/javascripts/checker_spec.js.coffee.erb'
7
8
  end
data/README.md CHANGED
@@ -8,7 +8,7 @@ This gem was created with following ideas in my head:
8
8
 
9
9
  ## Warning
10
10
 
11
- Algorithm implemented for password strength measurement is simple because I have no cryptography skills. Your help in enhancing it with pull requests or at least formal algorithm description (so I can implement it) will be hardly appreciated.
11
+ Algorithm implemented for password strength measurement is simple because I have no cryptography skills. Your help in enhancing it with pull requests or at least formal algorithm description (so I can implement it) will be strongly appreciated.
12
12
 
13
13
  ## Installation
14
14
 
@@ -52,4 +52,4 @@ CoffeeScript specs:
52
52
 
53
53
  Both specs are run against the same suite of password-estimates pairs defined at `spec/examples.json`.
54
54
 
55
- ## Any help in enhancing algorithm is appreciated.
55
+ ## Any help in enhancing algorithm is appreciated.
@@ -0,0 +1,40 @@
1
+ reduce = (arr, init, cb) ->
2
+ for item in arr
3
+ init = cb(init, item)
4
+ init
5
+
6
+ map = (arr, cb) ->
7
+ cb(x) for x in arr
8
+
9
+ uniq = (arr) ->
10
+ reduce arr, [], (memo, x) ->
11
+ memo.push(x) if memo.indexOf(x) == -1
12
+ memo
13
+
14
+ @PasswordStrengthValidator =
15
+ TOP_100_PASSWORDS: <%= ValidatesPasswordStrength::Checker::TOP_100_PASSWORDS.inspect %>
16
+
17
+ getPasswordStrength: (pwd) ->
18
+ if @TOP_100_PASSWORDS.indexOf(pwd) != -1
19
+ 1
20
+ else
21
+ result = @__normalizeResult [
22
+ [1, pwd.match(/[a-z]/)],
23
+ [1, pwd.match(/[A-Z]/)],
24
+ [1, pwd.match(/[0-9]/)],
25
+ [1, pwd.match(/[^a-zA-Z0-9]/)],
26
+ [3, pwd.length > 7],
27
+ [1, pwd.length > 9],
28
+ [2, uniq(pwd.split('')).length > 5]
29
+ ]
30
+ for str in @TOP_100_PASSWORDS
31
+ return Math.floor(result/2) if pwd.indexOf(str) != -1
32
+
33
+ return result
34
+
35
+
36
+ __normalizeResult: (result) ->
37
+ reduce(result, 0, (strength, res) ->
38
+ if res[1] then strength + res[0] else strength
39
+ ) * (10/reduce(map(result, (x) -> x[0]), 0, (memo, x) -> memo + x))
40
+
@@ -1,14 +1,21 @@
1
1
  module ValidatesPasswordStrength::Checker
2
+ TOP_100_PASSWORDS = %w(password 123456 12345678 1234 qwerty 12345 dragon pussy baseball football letmein monkey 696969 abc123 mustang michael shadow master jennifer 111111 2000 jordan superman harley 1234567 fuckme hunter fuckyou trustno1 ranger buster thomas tigger robert soccer fuck batman test pass killer hockey george charlie andrew michelle love sunshine jessica asshole 6969 pepper daniel access 123456789 654321 joshua maggie starwars silver william dallas yankees 123123 ashley 666666 hello amanda orange biteme freedom computer sexy nicole thunder ginger heather hammer summer corvette taylor fucker austin 1111 merlin matthew 121212 golfer princess cheese martin chelsea patrick richard diamond yellow bigdog secret asdfgh sparky cowboy)
3
+
2
4
  def self.get_password_strength(pwd)
3
- normalize_result [
4
- [1, pwd =~ /[a-z]/],
5
- [1, pwd =~ /[A-Z]/],
6
- [1, pwd =~ /[0-9]/],
7
- [1, pwd =~ /[^a-zA-Z0-9]/],
8
- [3, pwd.length > 7],
9
- [1, pwd.length > 9],
10
- [2, pwd.split('').uniq.length > 5]
11
- ]
5
+ if TOP_100_PASSWORDS.index(pwd)
6
+ 1
7
+ else
8
+ result = normalize_result [
9
+ [1, pwd =~ /[a-z]/],
10
+ [1, pwd =~ /[A-Z]/],
11
+ [1, pwd =~ /[0-9]/],
12
+ [1, pwd =~ /[^a-zA-Z0-9]/],
13
+ [3, pwd.length > 7],
14
+ [1, pwd.length > 9],
15
+ [2, pwd.split('').uniq.length > 5]
16
+ ]
17
+ TOP_100_PASSWORDS.any? { |str| pwd.index(str) } ? result / 2 : result
18
+ end
12
19
  end
13
20
 
14
21
  private
@@ -18,4 +25,4 @@ module ValidatesPasswordStrength::Checker
18
25
  res[1] ? strength + res[0] : strength
19
26
  end.to_f * (10.0/result.map(&:first).reduce(&:+))
20
27
  end
21
- end
28
+ end
@@ -1,3 +1,3 @@
1
1
  module ValidatesPasswordStrength
2
- VERSION = "0.0.1"
2
+ VERSION = "0.3.0"
3
3
  end
data/spec/examples.json CHANGED
@@ -3,5 +3,7 @@
3
3
  "asdfQWER1!" : 10,
4
4
  "a" : 1,
5
5
  "aA" : 2,
6
- "asdfghjk" : 6
7
- }
6
+ "qmfkburl" : 6,
7
+ "qwerty" : 1,
8
+ "qwerty123456789" : 4
9
+ }
data/spec/spec_helper.rb CHANGED
@@ -3,6 +3,6 @@ require 'json'
3
3
  require 'validates_password_strength'
4
4
 
5
5
  RSpec.configure do |config|
6
- config.color_enabled = true
7
- config.formatter = 'documentation'
8
- end
6
+ config.color = true
7
+ config.formatter = 'documentation'
8
+ end
@@ -1,9 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe ValidatesPasswordStrength::PasswordStrengthValidator do
3
+ describe ValidatesPasswordStrength::Checker do
4
4
  JSON.parse(File.open(File.expand_path('../../examples.json', __FILE__)).read).each do |pwd, score|
5
5
  it "gives #{score} for password '#{pwd}'" do
6
6
  ValidatesPasswordStrength::Checker.get_password_strength(pwd).should == score
7
7
  end
8
8
  end
9
- end
9
+ end
@@ -21,5 +21,5 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency 'bundler', '~> 1.3'
22
22
  spec.add_development_dependency 'rake'
23
23
 
24
- spec.add_dependency 'activemodel', '~> 3.2.0'
24
+ spec.add_dependency 'activemodel', '>= 3.2.0'
25
25
  end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validates_password_strength
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Shaydurov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-23 00:00:00.000000000 Z
11
+ date: 2014-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: activemodel
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: 3.2.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: 3.2.0
55
55
  description: This gem unions a server-side ActiveModel password strength validation
@@ -60,14 +60,14 @@ executables: []
60
60
  extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
- - .gitignore
63
+ - ".gitignore"
64
64
  - Gemfile
65
65
  - Guardfile
66
66
  - LICENSE.txt
67
67
  - README.md
68
68
  - Rakefile
69
69
  - app/assets/javascripts/jquery-validates_password_strength.js.coffee
70
- - app/assets/javascripts/validates_password_strength.js.coffee
70
+ - app/assets/javascripts/validates_password_strength.js.coffee.erb
71
71
  - lib/validates_password_strength.rb
72
72
  - lib/validates_password_strength/checker.rb
73
73
  - lib/validates_password_strength/password_strength_validator.rb
@@ -89,17 +89,17 @@ require_paths:
89
89
  - lib
90
90
  required_ruby_version: !ruby/object:Gem::Requirement
91
91
  requirements:
92
- - - '>='
92
+ - - ">="
93
93
  - !ruby/object:Gem::Version
94
94
  version: '0'
95
95
  required_rubygems_version: !ruby/object:Gem::Requirement
96
96
  requirements:
97
- - - '>='
97
+ - - ">="
98
98
  - !ruby/object:Gem::Version
99
99
  version: '0'
100
100
  requirements: []
101
101
  rubyforge_project:
102
- rubygems_version: 2.0.0.rc.2
102
+ rubygems_version: 2.2.2
103
103
  signing_key:
104
104
  specification_version: 4
105
105
  summary: ActiveModel and JS password strength estimation
@@ -1,30 +0,0 @@
1
- reduce = (arr, init, cb) ->
2
- for item in arr
3
- init = cb(init, item)
4
- init
5
-
6
- map = (arr, cb) ->
7
- cb(x) for x in arr
8
-
9
- uniq = (arr) ->
10
- reduce arr, [], (memo, x) ->
11
- memo.push(x) if memo.indexOf(x) == -1
12
- memo
13
-
14
- @PasswordStrengthValidator =
15
- getPasswordStrength: (pwd) ->
16
- @__normalizeResult [
17
- [1, pwd.match(/[a-z]/)],
18
- [1, pwd.match(/[A-Z]/)],
19
- [1, pwd.match(/[0-9]/)],
20
- [1, pwd.match(/[^a-zA-Z0-9]/)],
21
- [3, pwd.length > 7],
22
- [1, pwd.length > 9],
23
- [2, uniq(pwd.split('')).length > 5]
24
- ]
25
-
26
- __normalizeResult: (result) ->
27
- reduce(result, 0, (strength, res) ->
28
- if res[1] then strength + res[0] else strength
29
- ) * (10/reduce(map(result, (x) -> x[0]), 0, (memo, x) -> memo + x))
30
-