support bcrypt
This commit is contained in:
parent
b839fdc275
commit
7d618e78ff
3
Makefile
3
Makefile
|
@ -2,7 +2,7 @@ PROJECT = emqttd
|
|||
PROJECT_DESCRIPTION = Erlang MQTT Broker
|
||||
PROJECT_VERSION = 2.2
|
||||
|
||||
DEPS = goldrush gproc lager esockd mochiweb pbkdf2 lager_syslog
|
||||
DEPS = goldrush gproc lager esockd mochiweb pbkdf2 lager_syslog bcrypt
|
||||
|
||||
dep_goldrush = git https://github.com/basho/goldrush 0.1.9
|
||||
dep_gproc = git https://github.com/uwiger/gproc
|
||||
|
@ -12,6 +12,7 @@ dep_esockd = git https://github.com/emqtt/esockd emq22
|
|||
dep_mochiweb = git https://github.com/emqtt/mochiweb emq22
|
||||
dep_pbkdf2 = git https://github.com/emqtt/pbkdf2 2.0.1
|
||||
dep_lager_syslog = git https://github.com/basho/lager_syslog
|
||||
dep_bcrypt = git https://github.com/smarkets/erlang-bcrypt master
|
||||
|
||||
ERLC_OPTS += +'{parse_transform, lager_transform}'
|
||||
|
||||
|
|
|
@ -61,8 +61,15 @@ passwd_hash(sha, Password) ->
|
|||
passwd_hash(sha256, Password) ->
|
||||
hexstring(crypto:hash(sha256, Password));
|
||||
passwd_hash(pbkdf2,{Salt, Password, Macfun, Iterations, Dklen}) ->
|
||||
{ok,Hexstring} = pbkdf2:pbkdf2(Macfun, Password, Salt, Iterations, Dklen),
|
||||
pbkdf2:to_hex(Hexstring).
|
||||
case pbkdf2:pbkdf2(Macfun, Password, Salt, Iterations, Dklen) of
|
||||
{ok,Hexstring} -> pbkdf2:to_hex(Hexstring);
|
||||
{error, Error} -> lager:error("PasswdHash with pbkdf2 error:~p", [Error]), error
|
||||
end;
|
||||
passwd_hash(bcrypt, {Salt, Password}) ->
|
||||
case bcrypt:hashpw(Salt, Password) of
|
||||
{ok, HashPassword} -> list_to_binary(HashPassword);
|
||||
{error, Error}-> lager:error("PasswdHash with bcrypt error:~p", [Error]), error
|
||||
end.
|
||||
|
||||
hexstring(<<X:128/big-unsigned-integer>>) ->
|
||||
iolist_to_binary(io_lib:format("~32.16.0b", [X]));
|
||||
|
|
Loading…
Reference in New Issue