password_strong 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Binary file
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.2-p290
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in password_strong.gemspec
4
+ gemspec
@@ -0,0 +1,34 @@
1
+ = Introduction
2
+
3
+ Validate password with the follow rules:
4
+
5
+ * at least one downcased
6
+ * size (minimum 8 characters)
7
+ * combination of numbers, letters and symbols
8
+ * at least two numbers
9
+
10
+ = Install
11
+
12
+ sudo gem install password_strong
13
+
14
+ = Use
15
+
16
+ class User < ActiveRecord::Base
17
+
18
+ verify_strong :password
19
+
20
+ end
21
+
22
+ = License
23
+
24
+ (The MIT License)
25
+
26
+ Copyright © 2011:
27
+
28
+ * Lucas Allan (http://www.lucasallan.com.br)
29
+
30
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
31
+
32
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
33
+
34
+ THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,13 @@
1
+ require "password_strong/version"
2
+ require "password_strong/railtie" if defined? Rails
3
+ require "password_strong/model_additions"
4
+ module PasswordStrong
5
+
6
+ def self.check_strong(password)
7
+ (password =~ password_regexp) != nil
8
+ end
9
+
10
+ def self.password_regexp
11
+ /^.*(?=.{6,})(?=.*[a-z])(?=.*[A-Z])(?=.*[\d\W]).*$/
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ module PasswordStrong
2
+ module ModelAdditions
3
+ def verify_strong(attribute)
4
+ before_validation do
5
+ validates_format_of attribute, :with => PasswordStrong.password_regexp, :message => 'is not secure; use letters (uppercase and downcase), numbers and special characters'
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module PasswordStrong
2
+ class Railtie < Rails::Railtie
3
+ initializer 'password_strong.model_additions' do
4
+ ActiveSupport.on_load :active_record do
5
+ extend ModelAdditions
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module PasswordStrong
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "password_strong/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "password_strong"
7
+ s.version = PasswordStrong::VERSION
8
+ s.authors = ["Lucas Allan"]
9
+ s.email = ["lucas.allan@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Check password strength}
12
+ s.description = %q{Check password strength with ActiveRecord support}
13
+
14
+ s.rubyforge_project = "password_strong"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_development_dependency "rspec"
22
+ s.add_development_dependency "supermodel"
23
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ class User < SuperModel::Base
4
+ include ActiveModel::Validations::Callbacks
5
+ extend PasswordStrong::ModelAdditions
6
+ verify_strong :password
7
+ end
8
+
9
+ describe PasswordStrong::ModelAdditions do
10
+
11
+ it "should be valid" do
12
+ User.new(:password => "lucaS/al12").should be_valid
13
+ end
14
+
15
+ it "should not be valid" do
16
+ User.new(:password => "123456").should_not be_valid
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe PasswordStrong do
4
+
5
+ it "should not be just numbers" do
6
+ PasswordStrong.check_strong("123456").should be_false
7
+ end
8
+
9
+ it "should not be just letters" do
10
+ PasswordStrong.check_strong("lucasal").should be_false
11
+ end
12
+
13
+ it "should not be just letters and numbers" do
14
+ PasswordStrong.check_strong("lucasal12").should be_false
15
+ end
16
+
17
+ it "should have letters, numbers, special characters and at least one uppercase" do
18
+ PasswordStrong.check_strong("lucaS/al12").should_not be_false
19
+ end
20
+ end
@@ -0,0 +1,2 @@
1
+ require 'password_strong'
2
+ require 'supermodel'
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: password_strong
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Lucas Allan
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-13 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70313213849500 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70313213849500
25
+ - !ruby/object:Gem::Dependency
26
+ name: supermodel
27
+ requirement: &70313213849080 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70313213849080
36
+ description: Check password strength with ActiveRecord support
37
+ email:
38
+ - lucas.allan@gmail.com
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .DS_Store
44
+ - .gitignore
45
+ - .rvmrc
46
+ - Gemfile
47
+ - README.rdoc
48
+ - Rakefile
49
+ - lib/password_strong.rb
50
+ - lib/password_strong/model_additions.rb
51
+ - lib/password_strong/railtie.rb
52
+ - lib/password_strong/version.rb
53
+ - password_strong.gemspec
54
+ - spec/password_strong/model_additions_spec.rb
55
+ - spec/password_strong_spec.rb
56
+ - spec/spec_helper.rb
57
+ homepage: ''
58
+ licenses: []
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project: password_strong
77
+ rubygems_version: 1.8.10
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: Check password strength
81
+ test_files:
82
+ - spec/password_strong/model_additions_spec.rb
83
+ - spec/password_strong_spec.rb
84
+ - spec/spec_helper.rb