MFA enabled for every user already present

You can share your Lua Scripts with everybody here.
Post Reply
floppy
Posts: 4
Joined: Thu Nov 13, 2025 9:55 am

MFA enabled for every user already present

Post by floppy »

Good morning,
I need to enable MFA massively for all the 300+ users on my FTP server (a mixture of local users and users locally mapped to AD).
I tried using the code below as a scheduled task as i someone suggested online but it only switch on MFA for the first user. I'm having trouble troubleshooting it because i do not have any log (i.e. i don't even know where the print function actually prints. Can anybody help? is there another, easier, way?
Thanks

Code: Select all

do
  local domains = c_GetDomainList()
  for _, domain in pairs(domains) do
    local userlist_raw = c_GetUserList(domain)
    local userlist = Split(userlist_raw or "", "\n")

    for _, username in pairs(userlist) do
      if username ~= "" then
        local user = c_GetUser(domain, username)
        if user ~= nil then
          local changed = false

          -- Turn on TOTP for Web Client
          if user.enable_two_factor ~= 1 and user.enable_two_factor ~= true then
            user.enable_two_factor = 1
            changed = true
          end
          if changed == true then
            -- Preserve current password field per vendor examples before saving
            user.oldpassword = user.password
            -- Persist the updated user object
            AddUser(domain, user)
            print(string.format("[%-20s] Enabled TOTP for '%s'%s",domain, username))
          end
        end
      end
    end
  end
end
FTP
Site Admin
Posts: 2151
Joined: Tue Sep 29, 2009 6:09 am

Re: MFA enabled for every user already present

Post by FTP »

OK, maybe there is something wrong in the "print" line, please use the following modified Lua script, and you can also execute it under "Administration > Console", just click on the "Console" icon on the top-right:
Image

Code: Select all

do
  local domains = c_GetDomainList()
  for _, domain in pairs(domains) do
    local userlist_raw = c_GetUserList(domain)
    local userlist = Split(userlist_raw or "", "\n")

    for _, username in pairs(userlist) do
      if username ~= "" then
        local user = c_GetUser(domain, username)
        if user ~= nil then
          local changed = false

          if user.enable_two_factor ~= 1 and user.enable_two_factor ~= true then
            user.enable_two_factor = 1
            changed = true
          end
          if changed == true then
            user.oldpassword = user.password
            AddUser(domain, user)
            print(string.format("[%s] Enabled TOTP for '%s' \n",domain, username))
          end
        end
      end
    end
  end
end
Post Reply