Commit 167b5d49c4c79f96209dd1a236bedf4f04241b76
Fixed password == false crashes.
git-svn-id: http://bcrypt-ruby.rubyforge.org/svn/trunk@24 b1e0f299-433e-4bb3-9895-84128a6cfb6acodahale committed on 3/9/2007, 8:26:04 PM
Parent: 703d4f06feb9f60ff0ca99dfe5d9bf983de517ad
Files changed
lib/bcrypt.rb | changed |
spec/bcrypt/engine_spec.rb | changed |
spec/bcrypt/password_spec.rb | changed |
lib/bcrypt.rb | ||
---|---|---|
@@ -30,9 +30,9 @@ | ||
30 | 30 … | # a bcrypt() password hash. |
31 | 31 … | def self.hash(secret, salt) |
32 | 32 … | if valid_secret?(secret) |
33 | 33 … | if valid_salt?(salt) |
34 | - __bc_crypt(secret, salt) | |
34 … | + __bc_crypt(secret.to_s, salt) | |
35 | 35 … | else |
36 | 36 … | raise Errors::InvalidSalt.new("invalid salt") |
37 | 37 … | end |
38 | 38 … | else |
@@ -55,9 +55,9 @@ | ||
55 | 55 … | end |
56 | 56 … | |
57 | 57 … | # Returns true if +secret+ is a valid bcrypt() secret, false if not. |
58 | 58 … | def self.valid_secret?(secret) |
59 | - !secret.nil? | |
59 … | + secret.respond_to?(:to_s) | |
60 | 60 … | end |
61 | 61 … | |
62 | 62 … | # Returns the cost factor which will result in computation times less than +upper_time_limit_in_ms+. |
63 | 63 … | # |
spec/bcrypt/engine_spec.rb | ||
---|---|---|
@@ -42,10 +42,10 @@ | ||
42 | 42 … | lambda { BCrypt::Engine.hash(@password, 'nino') }.should raise_error(BCrypt::Errors::InvalidSalt) |
43 | 43 … | end |
44 | 44 … | |
45 | 45 … | specify "should raise an InvalidSecret error if the secret is invalid" do |
46 | - lambda { BCrypt::Engine.hash(nil, @salt) }.should raise_error(BCrypt::Errors::InvalidSecret) | |
47 | - lambda { BCrypt::Engine.hash(false, @salt) }.should raise_error(BCrypt::Errors::InvalidSecret) | |
46 … | + lambda { BCrypt::Engine.hash(nil, @salt) }.should_not raise_error(BCrypt::Errors::InvalidSecret) | |
47 … | + lambda { BCrypt::Engine.hash(false, @salt) }.should_not raise_error(BCrypt::Errors::InvalidSecret) | |
48 | 48 … | end |
49 | 49 … | |
50 | 50 … | specify "should be interoperable with other implementations" do |
51 | 51 … | # test vectors from the OpenWall implementation <http://www.openwall.com/crypt/> |
spec/bcrypt/password_spec.rb | ||
---|---|---|
@@ -14,10 +14,12 @@ | ||
14 | 14 … | specify "should return a valid bcrypt password" do |
15 | 15 … | lambda { BCrypt::Password.new(@password) }.should_not raise_error |
16 | 16 … | end |
17 | 17 … | |
18 | - specify "should raise an InvalidSecret exception if the secret is nil" do | |
19 | - lambda { BCrypt::Password.create(nil) }.should raise_error(BCrypt::Errors::InvalidSecret) | |
18 … | + specify "should behave normally if the secret not a string" do | |
19 … | + lambda { BCrypt::Password.create(nil) }.should_not raise_error(BCrypt::Errors::InvalidSecret) | |
20 … | + lambda { BCrypt::Password.create({:woo => "yeah"}) }.should_not raise_error(BCrypt::Errors::InvalidSecret) | |
21 … | + lambda { BCrypt::Password.create(false) }.should_not raise_error(BCrypt::Errors::InvalidSecret) | |
20 | 22 … | end |
21 | 23 … | end |
22 | 24 … | |
23 | 25 … | context "Reading a hashed password" do |
Built with git-ssb-web