fediauth/password_save.lua

28 lines
1.2 KiB
Lua
Raw Normal View History

-- save password for prevent change password during fediauth process
-- issue: https://forum.minetest.net/viewtopic.php?p=429275#p429275
function fediauth.save_passw(playername)
local auth_data = minetest.get_auth_handler().get_auth(playername)
if fediauth.storage:get_string(playername .. "_pwd") == "" then
minetest.log("action", "[fediauth] save password of '" .. playername .. "'")
minetest.set_player_password(playername, auth_data.password)
fediauth.storage:set_string(playername .. "_pwd", auth_data.password)
end
end
-- discard password
function fediauth.discard_passw(playername)
local auth_data = minetest.get_auth_handler().get_auth(playername)
local stored_pwd = fediauth.storage:get_string(playername .. "_pwd")
if stored_pwd ~= "" then
if stored_pwd == auth_data.password then
fediauth.storage:set_string(playername .. "_pwd", "")
else
minetest.log("warning", "[fediauth] '" .. playername .. "' attempt change password! Restoring")
minetest.kick_player(playername, "password protection violation")
minetest.set_player_password(playername, stored_pwd)
fediauth.storage:set_string(playername .. "_pwd", "")
end
end
end