소스 검색

atom_to_list(Username)

Feng Lee 9 년 전
부모
커밋
76851e58fb
2개의 변경된 파일4개의 추가작업 그리고 1개의 파일을 삭제
  1. 1 1
      rel/files/emqttd.test.config
  2. 3 0
      src/emqttd_auth_username.erl

+ 1 - 1
rel/files/emqttd.test.config

@@ -46,7 +46,7 @@
         %% Authetication. Anonymous Default
         %% Authetication. Anonymous Default
         {auth, [
         {auth, [
             %% Authentication with username, password
             %% Authentication with username, password
-            %{username, []},
+            {username, [{test, "password"}, {"test1", "password1"}]},
             
             
             %% Authentication with clientid
             %% Authentication with clientid
             %{clientid, [{password, no}, {file, "etc/clients.config"}]},
             %{clientid, [{password, no}, {file, "etc/clients.config"}]},

+ 3 - 0
src/emqttd_auth_username.erl

@@ -77,6 +77,9 @@ add_user(Username, Password) ->
     User = #?AUTH_USERNAME_TAB{username = Username, password = hash(Password)},
     User = #?AUTH_USERNAME_TAB{username = Username, password = hash(Password)},
     ret(mnesia:transaction(fun mnesia:write/1, [User])).
     ret(mnesia:transaction(fun mnesia:write/1, [User])).
 
 
+add_default_user(Username, Password) when is_atom(Username) ->
+    add_default_user(atom_to_list(Username), Password);
+
 add_default_user(Username, Password) ->
 add_default_user(Username, Password) ->
     add_user(iolist_to_binary(Username), iolist_to_binary(Password)).
     add_user(iolist_to_binary(Username), iolist_to_binary(Password)).