Permalink
Browse files

Changed BCrypt::Engine.hash to BCrypt::Engine.hash_secret to avoid Me…

…rb sorting issues. Thanks to Lee Pope for

the patch, including specs!
  • Loading branch information...
1 parent 17a8701 commit 1696fcde2d7720cd5da20e4c16a39e9455f7d16d @codahale codahale committed May 8, 2008
Showing with 14 additions and 12 deletions.
  1. +4 −2 CHANGELOG
  2. +4 −4 lib/bcrypt.rb
  3. +6 −6 spec/bcrypt/engine_spec.rb
View
@@ -15,5 +15,7 @@
- Fixed example code in the README [Winson]
- Fixed Solaris compatibility [Jeremy LaTrasse, Twitter crew]
-SVN Blah
- - Made exception classes descend from StandardError, not Exception [Dan42]
+HEAD
+ - Made exception classes descend from StandardError, not Exception [Dan42]
+ - Changed BCrypt::Engine.hash to BCrypt::Engine.hash_secret to avoid Merb
+ sorting issues. [Lee Pope]
View
@@ -28,7 +28,7 @@ class Engine
# Given a secret and a valid salt (see BCrypt::Engine.generate_salt) calculates
# a bcrypt() password hash.
- def self.hash(secret, salt)
+ def self.hash_secret(secret, salt)
if valid_secret?(secret)
if valid_salt?(salt)
__bc_crypt(secret.to_s, salt)
@@ -123,7 +123,7 @@ class << self
#
# @password = BCrypt::Password.create("my secret", :cost => 13)
def create(secret, options = { :cost => BCrypt::Engine::DEFAULT_COST })
- Password.new(BCrypt::Engine.hash(secret, BCrypt::Engine.generate_salt(options[:cost])))
+ Password.new(BCrypt::Engine.hash_secret(secret, BCrypt::Engine.generate_salt(options[:cost])))
end
end
@@ -139,7 +139,7 @@ def initialize(raw_hash)
# Compares a potential secret against the hash. Returns true if the secret is the original secret, false otherwise.
def ==(secret)
- super(BCrypt::Engine.hash(secret, @salt))
+ super(BCrypt::Engine.hash_secret(secret, @salt))
end
alias_method :is_password?, :==
@@ -158,4 +158,4 @@ def split_hash(h)
return v, c.to_i, h[0, 29], mash[-31, 31]
end
end
-end
+end
View
@@ -35,16 +35,16 @@
end
specify "should produce a string" do
- BCrypt::Engine.hash(@password, @salt).should be_an_instance_of(String)
+ BCrypt::Engine.hash_secret(@password, @salt).should be_an_instance_of(String)
end
specify "should raise an InvalidSalt error if the salt is invalid" do
- lambda { BCrypt::Engine.hash(@password, 'nino') }.should raise_error(BCrypt::Errors::InvalidSalt)
+ lambda { BCrypt::Engine.hash_secret(@password, 'nino') }.should raise_error(BCrypt::Errors::InvalidSalt)
end
specify "should raise an InvalidSecret error if the secret is invalid" do
- lambda { BCrypt::Engine.hash(nil, @salt) }.should_not raise_error(BCrypt::Errors::InvalidSecret)
- lambda { BCrypt::Engine.hash(false, @salt) }.should_not raise_error(BCrypt::Errors::InvalidSecret)
+ lambda { BCrypt::Engine.hash_secret(nil, @salt) }.should_not raise_error(BCrypt::Errors::InvalidSecret)
+ lambda { BCrypt::Engine.hash_secret(false, @salt) }.should_not raise_error(BCrypt::Errors::InvalidSecret)
end
specify "should be interoperable with other implementations" do
@@ -57,7 +57,7 @@
["0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", "$2a$05$abcdefghijklmnopqrstuu", "$2a$05$abcdefghijklmnopqrstuu5s2v8.iXieOjg/.AySBTTZIIVFJeBui"]
]
for secret, salt, test_vector in test_vectors
- BCrypt::Engine.hash(secret, salt).should eql(test_vector)
+ BCrypt::Engine.hash_secret(secret, salt).should eql(test_vector)
end
end
-end
+end

0 comments on commit 1696fcd

Please sign in to comment.