---
 man/mount.davfs.8 |    8 ++++++++
 src/mount_davfs.c |   34 +++++++++++++++++++++++++++-------
 src/mount_davfs.h |    1 +
 3 files changed, 36 insertions(+), 7 deletions(-)

diff --git a/man/mount.davfs.8 b/man/mount.davfs.8
index d147af4..838dfa3 100644
--- a/man/mount.davfs.8
+++ b/man/mount.davfs.8
@@ -507,6 +507,14 @@ proxy.mycompany.com     filomena  "my secret"
 /media/dav   webdav\-username   password
 .RE
 
+.PP
+If you have two-factor authentication enabled and if you can provide the token together with the password
+in the form of password:token, then add the string '2FA' as the forth parameter and you will be asked for
+token during mounting.
+.RS
+/media/dav   user-name   "p@ss\\"w0rd" 2FA
+.RE
+
 .PP
 Now the WebDAV resource may be mounted by user filomena invoking
 .RS
diff --git a/src/mount_davfs.c b/src/mount_davfs.c
index 6a5f829..18ba31c 100644
--- a/src/mount_davfs.c
+++ b/src/mount_davfs.c
@@ -1530,6 +1530,10 @@ delete_args(dav_args *args)
         memset(args->password, '\0', strlen(args->password));
         free(args->password);
     }
+    if (args->token) {
+        memset(args->token, '\0', strlen(args->token));
+        free(args->token);
+    }
     if (args->clicert)
         free(args->clicert);
     if (args->clicert_pw) {
@@ -2158,9 +2162,7 @@ read_config(dav_args *args, const char * filename, int system)
         char *parmv[parmc];
         int count;
         count = parse_line(line, parmc, parmv);
-
         if (count == 1) {
-
             if (*parmv[0] != '[' || *(parmv[0] + strlen(parmv[0]) - 1) != ']')
                 ERR_AT_LINE(filename, lineno, _("malformed line"));
             *(parmv[0] + strlen(parmv[0]) - 1) = '\0';
@@ -2301,7 +2303,7 @@ read_config(dav_args *args, const char * filename, int system)
                 ERR_AT_LINE(filename, lineno, _("unknown option"));
             }
 
-        } else if (count < 0 || count > 3) {
+        } else if (count < 0 || count > 4) {
 
             ERR_AT_LINE(filename, lineno, _("malformed line"));
         }
@@ -2396,14 +2398,14 @@ read_secrets(dav_args *args, const char *filename)
     int lineno = 1;
 
     while (length > 0) {
-        int parmc = 3;
+        int parmc = 4;
         char *parmv[parmc];
         int count;
         count = parse_line(line, parmc, parmv);
-        if (count != 0 && count != 3 && count != 2)
+        if (count != 0 && count != 4 && count != 3 && count != 2)
             ERR_AT_LINE(filename, lineno, _("malformed line"));
 
-        if (count == 2 || count == 3) {
+        if (count == 2 || count == 3 || count == 4) {
 
             char *scheme = NULL;
             char *host = NULL;
@@ -2441,10 +2443,28 @@ read_secrets(dav_args *args, const char *filename)
                     memset(args->password, '\0', strlen(args->password));
                     free(args->password);
                 }
+                if (args->token) {
+                    memset(args->token, '\0', strlen(args->token));
+                    free(args->token);
+                }
                 args->username = ne_strdup(parmv[1]);
-                if (count == 3)
+                if (count == 3 || count == 4)
                     args->password = ne_strdup(parmv[2]);
 
+		if (count == 4 && (0 == strcmp(ne_strdup(parmv[3]), "2FA"))) {
+		  args->token = user_input(_("2FA Token: "));
+		  size_t new_len = strlen(args->password) + strlen(args->token) + 2; // old pwd + ':' + token + \0
+		  char *new_pass = ne_calloc(new_len);
+		  if (args->password) {
+		    strcat(new_pass, args->password);
+		    strcat(new_pass, ":");
+		    strcat(new_pass, args->token);
+		    memset(args->password, '\0', strlen(args->password));
+                    free(args->password);
+		  }
+		  args->password = ne_strdup(new_pass);
+		}
+
             } else if (strcmp(parmv[0], "proxy") == 0
                        || (host && args->p_host
                            && strcmp(host, args->p_host) == 0
diff --git a/src/mount_davfs.h b/src/mount_davfs.h
index 1f234f0..76bdecc 100644
--- a/src/mount_davfs.h
+++ b/src/mount_davfs.h
@@ -60,6 +60,7 @@ typedef struct {
     char *cl_username;        /* Command line */
     char *password;           /* User secrets file, system secrets file */
     char *clicert;            /* User config file, system config file */
+    char *token;              /* User 2FA token */
     char *clicert_pw;         /* User secrets file, system secrets file */
     char *p_host;             /* User config file, sys conf f., environment */
     int p_port;               /* User config file, sys conf f., environment */
