summaryrefslogtreecommitdiff
path: root/src/ejabberd_auth.erl
diff options
context:
space:
mode:
authorPaweł Chmielowski <pchmielowski@process-one.net>2019-11-27 10:35:52 +0100
committerPaweł Chmielowski <pchmielowski@process-one.net>2019-11-27 10:35:52 +0100
commit71c44bff8bd18dea073c3e1e12ccc120b22a1828 (patch)
treec66bfef139738919966d4d6862d106ba3393a026 /src/ejabberd_auth.erl
parentMerge branch 'sabudaye-pg_prepared_statements' (diff)
Make convert_to_scram work with all backends
Diffstat (limited to 'src/ejabberd_auth.erl')
-rw-r--r--src/ejabberd_auth.erl23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/ejabberd_auth.erl b/src/ejabberd_auth.erl
index 9a7479e4..1fc05f8c 100644
--- a/src/ejabberd_auth.erl
+++ b/src/ejabberd_auth.erl
@@ -46,7 +46,7 @@
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).
--export([auth_modules/1]).
+-export([auth_modules/1, convert_to_scram/1]).
-include("scram.hrl").
-include("logger.hrl").
@@ -915,3 +915,24 @@ import(Server, {sql, _}, mnesia, <<"users">>, Fields) ->
ejabberd_auth_mnesia:import(Server, Fields);
import(_LServer, {sql, _}, sql, <<"users">>, _) ->
ok.
+
+-spec convert_to_scram(binary()) -> {error, any()} | ok.
+convert_to_scram(Server) ->
+ LServer = jid:nameprep(Server),
+ if
+ LServer == error;
+ LServer == <<>> ->
+ {error, {incorrect_server_name, Server}};
+ true ->
+ lists:foreach(
+ fun({U, S}) ->
+ case get_password(U, S) of
+ Pass when is_binary(Pass) ->
+ SPass = password_to_scram(Pass),
+ set_password(U, S, SPass);
+ _ ->
+ ok
+ end
+ end, get_users(LServer)),
+ ok
+ end.