secure-password 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5d692430f3c8be0c6ccad21f224e08ce0b93d0c6
4
+ data.tar.gz: de8c69c09c5e080cd36b0846c1764feb066364b4
5
+ SHA512:
6
+ metadata.gz: 2330cb1d97b33ddcdbe0a46041f45094c8f0de46ec9c381017260065c0b79ef6cc590515927eab5f84546464554034db0d7f77852501a0680abcd438404984e1
7
+ data.tar.gz: 9748b9b6d87186372fcca5d9fe883715fa5082cdf4cfb12272e61cb078be6841c37f53ac03dec7c20225a9d929c41befd75c2d60257e8d16222a527ef21517b2
data/.gems ADDED
@@ -0,0 +1,2 @@
1
+ bcrypt -v 3.1.9
2
+ cutest -v 1.2.2
@@ -0,0 +1,64 @@
1
+ secure-password
2
+ ===============
3
+
4
+ Small library to store a secure hash of your users' passwords.
5
+ It uses the [Bcrypt][bcrypt-ruby] password hashing algorithm.
6
+
7
+ Usage
8
+ -----
9
+
10
+ ```ruby
11
+ require "secure_password"
12
+
13
+ class User
14
+ include SecurePassword
15
+
16
+ # A `password_digest` attribute is required.
17
+ attr_accessor :password_digest
18
+ end
19
+
20
+ user = User.new
21
+ user.password = "123456"
22
+
23
+ user.password_digest
24
+ # => "$2a$10$rHxX0jSF14JErSjrrFTB9exXPRkbzpq9.mg9nV2vHZVIjOqKQNvQe"
25
+
26
+ user.authenticate("nopassword")
27
+ # => false
28
+
29
+ user.authenticate("123456")
30
+ # => true
31
+ ```
32
+
33
+ It's important to note that BCrypt hash function can handle
34
+ maximum 72 characters. It's recommended to validate the length
35
+ of a given password before creating a record.
36
+
37
+ The next example uses [Scrivener][scrivener]:
38
+
39
+ ```ruby
40
+ class Signup
41
+ attr_accessor :username
42
+ attr_accessor :password
43
+
44
+ def validate
45
+ assert_present(:username)
46
+ assert_length(:password, 8..72)
47
+ end
48
+ end
49
+
50
+ signup = Signup.new(params)
51
+ if signup.valid?
52
+ User.create(signup.attributes)
53
+ end
54
+ ```
55
+
56
+ Installation
57
+ ------------
58
+
59
+ ```
60
+ $ gem install secure-password
61
+ ```
62
+
63
+ [scrivener]: https://github.com/soveran/scrivener
64
+ [bcrypt-ruby]: https://github.com/codahale/bcrypt-ruby
@@ -0,0 +1,11 @@
1
+ require "bcrypt"
2
+
3
+ module SecurePassword
4
+ def authenticate(unencrypted)
5
+ return BCrypt::Password.new(password_digest) == unencrypted
6
+ end
7
+
8
+ def password=(unencrypted)
9
+ self.password_digest = BCrypt::Password.create(unencrypted)
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ .PHONY: test
2
+
3
+ gem:
4
+ gem build secure-password.gemspec
5
+
6
+ test:
7
+ cutest test/*.rb
@@ -0,0 +1,15 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "secure-password"
3
+ s.version = "1.0.0"
4
+ s.summary = "Securing your users' passwords."
5
+ s.description = s.summary
6
+ s.authors = ["Francesco Rodríguez", "Mayn Kjær"]
7
+ s.email = ["frodsan@me.com", "mayn.kjaer@gmail.com"]
8
+ s.homepage = "https://github.com/harmoni-io/secure-password"
9
+ s.license = "MIT"
10
+
11
+ s.files = `git ls-files`.split("\n")
12
+
13
+ s.add_dependency("bcrypt", "~> 3.1")
14
+ s.add_development_dependency("cutest")
15
+ end
@@ -0,0 +1,29 @@
1
+ require "cutest"
2
+ require_relative "../lib/secure_password"
3
+
4
+ class User
5
+ include SecurePassword
6
+
7
+ attr_accessor :password_digest
8
+ end
9
+
10
+ test "sets hashed password" do
11
+ user = User.new
12
+ user.password = "123456"
13
+
14
+ assert BCrypt::Password.valid_hash?(user.password_digest)
15
+ end
16
+
17
+ test "successful authentication" do
18
+ user = User.new
19
+ user.password = "123456"
20
+
21
+ assert user.authenticate("123456")
22
+ end
23
+
24
+ test "failed authentication" do
25
+ user = User.new
26
+ user.password = "123456"
27
+
28
+ assert !(user.authenticate("xxxxxx"))
29
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: secure-password
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Francesco Rodríguez
8
+ - Mayn Kjær
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-12-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bcrypt
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '3.1'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '3.1'
28
+ - !ruby/object:Gem::Dependency
29
+ name: cutest
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ description: Securing your users' passwords.
43
+ email:
44
+ - frodsan@me.com
45
+ - mayn.kjaer@gmail.com
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".gems"
51
+ - README.md
52
+ - lib/secure_password.rb
53
+ - makefile
54
+ - secure-password.gemspec
55
+ - test/secure_password.rb
56
+ homepage: https://github.com/harmoni-io/secure-password
57
+ licenses:
58
+ - MIT
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.2.2
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: Securing your users' passwords.
80
+ test_files: []