fix: default_password should not be empty

This commit is contained in:
zhongwencool 2022-06-27 14:33:37 +08:00
parent fd22639bcb
commit ab2e477ffd
1 changed files with 6 additions and 3 deletions

View File

@ -22,6 +22,7 @@
-include("emqx_dashboard.hrl"). -include("emqx_dashboard.hrl").
-include_lib("emqx/include/logger.hrl"). -include_lib("emqx/include/logger.hrl").
-define(DEFAULT_PASSWORD, <<"public">>).
-boot_mnesia({mnesia, [boot]}). -boot_mnesia({mnesia, [boot]}).
-copy_mnesia({mnesia, [copy]}). -copy_mnesia({mnesia, [copy]}).
@ -284,8 +285,10 @@ ensure_default_user_in_db(Username) ->
initial_default_user_passwd_hashed() -> initial_default_user_passwd_hashed() ->
case get_default_user_passwd_hashed_from_pt() of case get_default_user_passwd_hashed_from_pt() of
Empty when ?EMPTY_KEY(Empty) -> Empty when ?EMPTY_KEY(Empty) ->
Pwd = binenv(default_user_passwd), case binenv(default_user_passwd) of
hash(Pwd); Empty when ?EMPTY_KEY(Empty) -> hash(?DEFAULT_PASSWORD);
Pwd -> hash(Pwd)
end;
PwdHash -> PwdHash ->
PwdHash PwdHash
end. end.
@ -300,7 +303,7 @@ get_default_user_passwd_hashed_from_pt() ->
persistent_term:get({?MODULE, default_user_passwd_hashed}, <<>>). persistent_term:get({?MODULE, default_user_passwd_hashed}, <<>>).
maybe_warn_default_pwd() -> maybe_warn_default_pwd() ->
case is_valid_pwd(initial_default_user_passwd_hashed(), <<"public">>) of case is_valid_pwd(initial_default_user_passwd_hashed(), ?DEFAULT_PASSWORD) of
true -> true ->
?LOG(warning, ?LOG(warning,
"[Dashboard] Using default password for dashboard 'admin' user. " "[Dashboard] Using default password for dashboard 'admin' user. "