secure-password 1.0.2 → 1.1.0

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
  SHA1:
3
- metadata.gz: 05216644d093a1d925c62514370759127eab3cc3
4
- data.tar.gz: 4f9abc8a7ff51b4ead9fd4e581dfe63dc530f67b
3
+ metadata.gz: 2329db84355b9783f598d01dcb8bfbdf6a7b908c
4
+ data.tar.gz: c9e8b2a617d30d53e7f892cc6e37423237ec7836
5
5
  SHA512:
6
- metadata.gz: e13f40b2810a8cb18242086d354d2de8442a3ffefea23faa9559b7e529414be503ad9367ad122e605898d115b986067c646a69ef3f2ad88686a16cce172c50a2
7
- data.tar.gz: 899a1e47e91f97a88363a5e2a8e9e2f1d0b3863a96c271d8e0af93aa80796397035e57c249da5817c6445407e326eabc48dc11694d057eebcdc590a5ff111a65
6
+ metadata.gz: fc310db147d696aa7eeeab6cf237709f5658a047facab178c1af5ef2b5388249c09bafdebcabf6323a984af55893d2cca086093fbba07ad81925539d3a115362
7
+ data.tar.gz: 884ba8dbed565f78fad6020b3c2dd8362d9aaaf0822e0a8a26d3b54eb9b6c5e7cab2d66f71262e295cd89ebb23c8e06d75e8d67dd43413472a5a1255324c5508
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- secure-password
1
+ secure-password [![Build Status](https://travis-ci.org/frodsan/secure-password.svg)](https://travis-ci.org/frodsan/secure-password)
2
2
  ===============
3
3
 
4
4
  Set and authenticate against [bcrypt][bcrypt] passwords.
@@ -80,7 +80,7 @@ Bcrypt's cost factor
80
80
  The default cost factor used by `BCrypt` is `10`. To change it, use:
81
81
 
82
82
  ```ruby
83
- BCrypt::Engine.cost = 12
83
+ SecurePassword.cost = 12
84
84
  ```
85
85
 
86
86
  Check ["Cost Factors"][cost-factors] section for more information.
@@ -93,7 +93,9 @@ However, tests don't need this security measures. To speed up your tests,
93
93
  you can decrease the default cost factor to the minimum:
94
94
 
95
95
  ```ruby
96
- BCrypt::Engine.cost = BCrypt::Engine::MIN_COST
96
+ require "secure_password/testing"
97
+
98
+ SecurePassword.cost # => 4
97
99
  ```
98
100
 
99
101
  Contributing
@@ -3,11 +3,21 @@
3
3
  require "bcrypt"
4
4
 
5
5
  module SecurePassword
6
+ @cost = nil
7
+
8
+ def self.cost
9
+ @cost || BCrypt::Engine.cost
10
+ end
11
+
12
+ def self.cost=(cost)
13
+ @cost = cost
14
+ end
15
+
6
16
  def authenticate(unencrypted)
7
17
  BCrypt::Password.new(password_digest) == unencrypted
8
18
  end
9
19
 
10
- def password=(unencrypted)
11
- self.password_digest = BCrypt::Password.create(unencrypted)
20
+ def password=(unencrypted, cost: SecurePassword.cost)
21
+ self.password_digest = BCrypt::Password.create(unencrypted, cost: cost)
12
22
  end
13
23
  end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ SecurePassword.cost = BCrypt::Engine::MIN_COST
@@ -5,6 +5,7 @@ require "minitest/autorun"
5
5
  require "minitest/pride"
6
6
  require "minitest/sugar"
7
7
  require_relative "../lib/secure_password"
8
+ require_relative "../lib/secure_password/testing"
8
9
 
9
10
  class User
10
11
  include SecurePassword
@@ -12,8 +13,6 @@ class User
12
13
  attr_accessor :password_digest
13
14
  end
14
15
 
15
- BCrypt::Engine.cost = BCrypt::Engine::MIN_COST
16
-
17
16
  class SecurePasswordTest < Minitest::Test
18
17
  test "sets hashed password" do
19
18
  user = User.new
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: secure-password
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francesco Rodríguez
@@ -89,6 +89,7 @@ files:
89
89
  - LICENSE
90
90
  - README.md
91
91
  - lib/secure_password.rb
92
+ - lib/secure_password/testing.rb
92
93
  - test/secure_password_test.rb
93
94
  homepage: https://github.com/frodsan/secure-password
94
95
  licenses: