Skip to content

Commit

Permalink
Dont update password hash if given current password (#586)
Browse files Browse the repository at this point in the history
  • Loading branch information
spuun authored Nov 8, 2023
1 parent eeef59c commit f0d5741
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .ameba.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ Lint/NotNil:
Enabled: true
Severity: Warning

Lint/DocumentationAdmonition:
Enabled: false

# Problems found: 2
# Run `ameba --only Metrics/CyclomaticComplexity` for details
Metrics/CyclomaticComplexity:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Don't update user's password hash if given password is the same as current [#586](https://github.com/cloudamqp/lavinmq/pull/586)

## [1.2.5] - 2023-11-06

### Added
Expand Down
18 changes: 18 additions & 0 deletions spec/users_spec.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
require "./spec_helper"

describe LavinMQ::User do
describe "#update_password" do
it "should not update password hash when given same password as current" do
u = LavinMQ::User.create("username", "password", "sha256", [] of LavinMQ::Tag)
password_hash_before = u.password
u.update_password("password")
u.password.should eq password_hash_before
end

it "should update password hash when given other password than current" do
u = LavinMQ::User.create("username", "password", "sha256", [] of LavinMQ::Tag)
password_hash_before = u.password
u.update_password("other")
u.password.should_not eq password_hash_before
end
end
end

describe LavinMQ::Server do
it "rejects invalid password" do
expect_raises(AMQP::Client::Connection::ClosedException) do
Expand Down
1 change: 1 addition & 0 deletions src/lavinmq/user.cr
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ module LavinMQ
end

def update_password(password, hash_algorithm = "sha256")
return if @password.try &.verify(password)
@password = User.hash_password(password, hash_algorithm)
end

Expand Down

0 comments on commit f0d5741

Please sign in to comment.