Diff

plugins/mod_auth_internal_plain.lua @ 10914:0d7d71dee0a0 0.11

mod_auth_internal_*: Apply saslprep to passwords Related to #1560
author Kim Alvefur <zash@zash.se>
date Sat, 23 May 2020 14:17:04 +0200
parent 8057:4a9275594981
child 11544:c98aebe601f9
line wrap: on
line diff
--- a/plugins/mod_auth_internal_plain.lua	Fri May 22 21:05:45 2020 +0200
+++ b/plugins/mod_auth_internal_plain.lua	Sat May 23 14:17:04 2020 +0200
@@ -8,6 +8,7 @@
 
 local usermanager = require "core.usermanager";
 local new_sasl = require "util.sasl".new;
+local saslprep = require "util.encodings".stringprep.saslprep;
 
 local log = module._log;
 local host = module.host;
@@ -20,8 +21,12 @@
 function provider.test_password(username, password)
 	log("debug", "test password for user '%s'", username);
 	local credentials = accounts:get(username) or {};
+	password = saslprep(password);
+	if not password then
+		return nil, "Password fails SASLprep.";
+	end
 
-	if password == credentials.password then
+	if password == saslprep(credentials.password) then
 		return true;
 	else
 		return nil, "Auth failed. Invalid username or password.";
@@ -35,6 +40,10 @@
 
 function provider.set_password(username, password)
 	log("debug", "set_password for username '%s'", username);
+	password = saslprep(password);
+	if not password then
+		return nil, "Password fails SASLprep.";
+	end
 	local account = accounts:get(username);
 	if account then
 		account.password = password;
@@ -57,6 +66,10 @@
 end
 
 function provider.create_user(username, password)
+	password = saslprep(password);
+	if not password then
+		return nil, "Password fails SASLprep.";
+	end
 	return accounts:set(username, {password = password});
 end