fix(authn): fix bad type of hash
This commit is contained in:
parent
c64637ca39
commit
29fb9b3361
|
@ -62,7 +62,7 @@ check_password(undefined, _Selected, _State) ->
|
||||||
check_password(Password,
|
check_password(Password,
|
||||||
#{<<"password_hash">> := Hash},
|
#{<<"password_hash">> := Hash},
|
||||||
#{password_hash_algorithm := bcrypt}) ->
|
#{password_hash_algorithm := bcrypt}) ->
|
||||||
case {ok, Hash} =:= bcrypt:hashpw(Password, Hash) of
|
case {ok, to_list(Hash)} =:= bcrypt:hashpw(Password, Hash) of
|
||||||
true -> ok;
|
true -> ok;
|
||||||
false -> {error, bad_username_or_password}
|
false -> {error, bad_username_or_password}
|
||||||
end;
|
end;
|
||||||
|
@ -100,3 +100,7 @@ convert_to_sql_param(undefined) ->
|
||||||
null;
|
null;
|
||||||
convert_to_sql_param(V) ->
|
convert_to_sql_param(V) ->
|
||||||
bin(V).
|
bin(V).
|
||||||
|
|
||||||
|
to_list(L) when is_list(L) -> L;
|
||||||
|
to_list(L) when is_binary(L) -> binary_to_list(L);
|
||||||
|
to_list(X) -> X.
|
||||||
|
|
|
@ -205,7 +205,7 @@ check_password(Password,
|
||||||
undefined ->
|
undefined ->
|
||||||
{error, {cannot_find_password_hash_field, PasswordHashField}};
|
{error, {cannot_find_password_hash_field, PasswordHashField}};
|
||||||
Hash ->
|
Hash ->
|
||||||
case {ok, Hash} =:= bcrypt:hashpw(Password, Hash) of
|
case {ok, to_list(Hash)} =:= bcrypt:hashpw(Password, Hash) of
|
||||||
true -> ok;
|
true -> ok;
|
||||||
false -> {error, bad_username_or_password}
|
false -> {error, bad_username_or_password}
|
||||||
end
|
end
|
||||||
|
@ -238,3 +238,7 @@ hash(Algorithm, Password, Salt, prefix) ->
|
||||||
emqx_passwd:hash(Algorithm, <<Salt/binary, Password/binary>>);
|
emqx_passwd:hash(Algorithm, <<Salt/binary, Password/binary>>);
|
||||||
hash(Algorithm, Password, Salt, suffix) ->
|
hash(Algorithm, Password, Salt, suffix) ->
|
||||||
emqx_passwd:hash(Algorithm, <<Password/binary, Salt/binary>>).
|
emqx_passwd:hash(Algorithm, <<Password/binary, Salt/binary>>).
|
||||||
|
|
||||||
|
to_list(L) when is_list(L) -> L;
|
||||||
|
to_list(L) when is_binary(L) -> binary_to_list(L);
|
||||||
|
to_list(X) -> X.
|
||||||
|
|
Loading…
Reference in New Issue