git ssb

0+

dangerousbeans / %aPBe2k3ugtjBr4rrsU1…



Commit 167b5d49c4c79f96209dd1a236bedf4f04241b76

Fixed password == false crashes.

git-svn-id: http://bcrypt-ruby.rubyforge.org/svn/trunk@24 b1e0f299-433e-4bb3-9895-84128a6cfb6a
codahale committed on 3/9/2007, 8:26:04 PM
Parent: 703d4f06feb9f60ff0ca99dfe5d9bf983de517ad

Files changed

lib/bcrypt.rbchanged
spec/bcrypt/engine_spec.rbchanged
spec/bcrypt/password_spec.rbchanged
lib/bcrypt.rbView
@@ -30,9 +30,9 @@
3030 # a bcrypt() password hash.
3131 def self.hash(secret, salt)
3232 if valid_secret?(secret)
3333 if valid_salt?(salt)
34- __bc_crypt(secret, salt)
34 + __bc_crypt(secret.to_s, salt)
3535 else
3636 raise Errors::InvalidSalt.new("invalid salt")
3737 end
3838 else
@@ -55,9 +55,9 @@
5555 end
5656
5757 # Returns true if +secret+ is a valid bcrypt() secret, false if not.
5858 def self.valid_secret?(secret)
59- !secret.nil?
59 + secret.respond_to?(:to_s)
6060 end
6161
6262 # Returns the cost factor which will result in computation times less than +upper_time_limit_in_ms+.
6363 #
spec/bcrypt/engine_spec.rbView
@@ -42,10 +42,10 @@
4242 lambda { BCrypt::Engine.hash(@password, 'nino') }.should raise_error(BCrypt::Errors::InvalidSalt)
4343 end
4444
4545 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)
4848 end
4949
5050 specify "should be interoperable with other implementations" do
5151 # test vectors from the OpenWall implementation <http://www.openwall.com/crypt/>
spec/bcrypt/password_spec.rbView
@@ -14,10 +14,12 @@
1414 specify "should return a valid bcrypt password" do
1515 lambda { BCrypt::Password.new(@password) }.should_not raise_error
1616 end
1717
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)
2022 end
2123 end
2224
2325 context "Reading a hashed password" do

Built with git-ssb-web