From ca4cdfe4ee71c5bf676e441f86acc947068adaf6 Mon Sep 17 00:00:00 2001 From: Feng Lee Date: Wed, 18 Jul 2018 23:29:20 +0800 Subject: [PATCH] Move the passwd_hash/2 function to emqx-passwd project --- src/emqx_auth_mod.erl | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/src/emqx_auth_mod.erl b/src/emqx_auth_mod.erl index a5c3844a9..65298ef9b 100644 --- a/src/emqx_auth_mod.erl +++ b/src/emqx_auth_mod.erl @@ -16,10 +16,6 @@ -include("emqx.hrl"). --export([passwd_hash/2]). - --type(hash_type() :: plain | md5 | sha | sha256 | pbkdf2 | bcrypt). - %%-------------------------------------------------------------------- %% Authentication behavihour %%-------------------------------------------------------------------- @@ -46,33 +42,3 @@ behaviour_info(_Other) -> -endif. -%% @doc Password Hash --spec(passwd_hash(hash_type(), binary() | tuple()) -> binary()). -passwd_hash(plain, Password) -> - Password; -passwd_hash(md5, Password) -> - hexstring(crypto:hash(md5, Password)); -passwd_hash(sha, Password) -> - hexstring(crypto:hash(sha, Password)); -passwd_hash(sha256, Password) -> - hexstring(crypto:hash(sha256, Password)); -passwd_hash(pbkdf2, {Salt, Password, Macfun, Iterations, Dklen}) -> - case pbkdf2:pbkdf2(Macfun, Password, Salt, Iterations, Dklen) of - {ok, Hexstring} -> pbkdf2:to_hex(Hexstring); - {error, Error} -> - emqx_logger:error("[AuthMod] PasswdHash with pbkdf2 error:~p", [Error]), <<>> - end; -passwd_hash(bcrypt, {Salt, Password}) -> - case bcrypt:hashpw(Password, Salt) of - {ok, HashPassword} -> list_to_binary(HashPassword); - {error, Error}-> - emqx_logger:error("[AuthMod] PasswdHash with bcrypt error:~p", [Error]), <<>> - end. - -hexstring(<>) -> - iolist_to_binary(io_lib:format("~32.16.0b", [X])); -hexstring(<>) -> - iolist_to_binary(io_lib:format("~40.16.0b", [X])); -hexstring(<>) -> - iolist_to_binary(io_lib:format("~64.16.0b", [X])). -