summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Klishin <mklishin@pivotal.io>2015-09-17 14:23:53 +0300
committerMichael Klishin <mklishin@pivotal.io>2015-09-17 14:23:53 +0300
commit571f1a1722674fcef8705b96051c84eabc1c9ca0 (patch)
treece339e7096e261f66e4a034726cf9a3066224d58 /src
parent9bfb85c26576d10331e4bee9c1602eb5844ffee3 (diff)
downloadrabbitmq-server-git-571f1a1722674fcef8705b96051c84eabc1c9ca0.tar.gz
Refactoring, per feedback from @videlalvaro
Diffstat (limited to 'src')
-rw-r--r--src/rabbit_auth_backend_internal.erl13
-rw-r--r--src/rabbit_password.erl7
2 files changed, 12 insertions, 8 deletions
diff --git a/src/rabbit_auth_backend_internal.erl b/src/rabbit_auth_backend_internal.erl
index c5db74833c..16d2bfe655 100644
--- a/src/rabbit_auth_backend_internal.erl
+++ b/src/rabbit_auth_backend_internal.erl
@@ -25,7 +25,7 @@
-export([add_user/2, delete_user/1, lookup_user/1,
change_password/2, clear_password/1,
- hash_password/1, change_password_hash/2,
+ hash_password/2, change_password_hash/2,
set_tags/2, set_permissions/5, clear_permissions/2]).
-export([user_info_keys/0, perms_info_keys/0,
user_perms_info_keys/0, vhost_perms_info_keys/0,
@@ -51,7 +51,7 @@
-spec(change_password/2 :: (rabbit_types:username(), rabbit_types:password())
-> 'ok').
-spec(clear_password/1 :: (rabbit_types:username()) -> 'ok').
--spec(hash_password/1 :: (rabbit_types:password())
+-spec(hash_password/2 :: (module(), rabbit_types:password())
-> rabbit_types:password_hash()).
-spec(change_password_hash/2 :: (rabbit_types:username(),
rabbit_types:password_hash()) -> 'ok').
@@ -167,7 +167,7 @@ add_user(Username, Password) ->
%% record, so we retrieve it here one more time
HashingMod = rabbit_password:hashing_mod(),
User = #internal_user{username = Username,
- password_hash = hash_password(Password),
+ password_hash = hash_password(HashingMod, Password),
tags = [],
hashing_algorithm = HashingMod},
R = rabbit_misc:execute_mnesia_transaction(
@@ -208,7 +208,8 @@ lookup_user(Username) ->
change_password(Username, Password) ->
rabbit_log:info("Changing password for '~s'~n", [Username]),
- R = change_password_hash(Username, hash_password(Password)),
+ R = change_password_hash(Username,
+ hash_password(rabbit_password:hashing_mod(), Password)),
rabbit_event:notify(user_password_changed, [{name, Username}]),
R.
@@ -218,8 +219,8 @@ clear_password(Username) ->
rabbit_event:notify(user_password_cleared, [{name, Username}]),
R.
-hash_password(Cleartext) ->
- rabbit_password:hash(Cleartext).
+hash_password(HashingMod, Cleartext) ->
+ rabbit_password:hash(HashingMod, Cleartext).
change_password_hash(Username, PasswordHash) ->
update_user(Username, fun(User) ->
diff --git a/src/rabbit_password.erl b/src/rabbit_password.erl
index 50c106244c..e620acb542 100644
--- a/src/rabbit_password.erl
+++ b/src/rabbit_password.erl
@@ -22,12 +22,15 @@
%% API
%%
--export([hash/1, generate_salt/0, salted_hash/2, salted_hash/3,
+-export([hash/1, hash/2, generate_salt/0, salted_hash/2, salted_hash/3,
hashing_mod/0, hashing_mod/1]).
hash(Cleartext) ->
+ hash(hashing_mod(), Cleartext).
+
+hash(HashingMod, Cleartext) ->
SaltBin = generate_salt(),
- Hash = salted_hash(SaltBin, Cleartext),
+ Hash = salted_hash(HashingMod, SaltBin, Cleartext),
<<SaltBin/binary, Hash/binary>>.
generate_salt() ->