Skip to content

Commit

Permalink
Merge pull request #227 from nathanKramer/fix/valid-hash-return-type
Browse files Browse the repository at this point in the history
Ensure valid_hash? returns a Boolean
  • Loading branch information
tenderlove committed Jul 21, 2020
2 parents bdaa2fa + eb567cb commit a4528cf
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/bcrypt/password.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def create(secret, options = {})
end

def valid_hash?(h)
h =~ /^\$[0-9a-z]{2}\$[0-9]{2}\$[A-Za-z0-9\.\/]{53}$/
/^\$[0-9a-z]{2}\$[0-9]{2}\$[A-Za-z0-9\.\/]{53}$/ === h
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/bcrypt/password_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@

describe "Validating a password hash" do
specify "should not accept an invalid password" do
expect(BCrypt::Password.valid_hash?("i_am_so_not_valid")).to be_falsey
expect(BCrypt::Password.valid_hash?("i_am_so_not_valid")).to be(false)
end
specify "should accept a valid password" do
expect(BCrypt::Password.valid_hash?(BCrypt::Password.create "i_am_so_valid")).to be_truthy
expect(BCrypt::Password.valid_hash?(BCrypt::Password.create "i_am_so_valid")).to be(true)
end
end

0 comments on commit a4528cf

Please sign in to comment.