03b9a7
diff --git a/tools/cachemgr.cc b/tools/cachemgr.cc
03b9a7
index 1ec4e15..fb5146e 100644
03b9a7
--- a/tools/cachemgr.cc
03b9a7
+++ b/tools/cachemgr.cc
03b9a7
@@ -354,7 +354,7 @@ auth_html(const char *host, int port, const char *user_name)
03b9a7
 
03b9a7
     printf("Manager name:
03b9a7
 
03b9a7
-    printf("size=\"30\" VALUE=\"%s\">\n", user_name);
03b9a7
+    printf("size=\"30\" VALUE=\"%s\">\n", rfc1738_escape(user_name));
03b9a7
 
03b9a7
     printf("Password:
03b9a7
 
03b9a7
@@ -418,7 +418,7 @@ menu_url(cachemgr_request * req, const char *action)
03b9a7
              script_name,
03b9a7
              req->hostname,
03b9a7
              req->port,
03b9a7
-             safe_str(req->user_name),
03b9a7
+             rfc1738_escape(safe_str(req->user_name)),
03b9a7
              action,
03b9a7
              safe_str(req->pub_auth));
03b9a7
     return url;
03b9a7
@@ -1073,8 +1073,8 @@ make_pub_auth(cachemgr_request * req)
03b9a7
     const int bufLen = snprintf(buf, sizeof(buf), "%s|%d|%s|%s",
03b9a7
                                 req->hostname,
03b9a7
                                 (int) now,
03b9a7
-                                req->user_name ? req->user_name : "",
03b9a7
-                                req->passwd);
03b9a7
+                                rfc1738_escape(safe_str(req->user_name)),
03b9a7
+                                rfc1738_escape(req->passwd));
03b9a7
     debug("cmgr: pre-encoded for pub: %s\n", buf);
03b9a7
 
03b9a7
     const int encodedLen = base64_encode_len(bufLen);
03b9a7
@@ -1089,8 +1089,6 @@ decode_pub_auth(cachemgr_request * req)
03b9a7
     char *buf;
03b9a7
     const char *host_name;
03b9a7
     const char *time_str;
03b9a7
-    const char *user_name;
03b9a7
-    const char *passwd;
03b9a7
 
03b9a7
     debug("cmgr: decoding pub: '%s'\n", safe_str(req->pub_auth));
03b9a7
     safe_free(req->passwd);
03b9a7
@@ -1119,17 +1117,21 @@ decode_pub_auth(cachemgr_request * req)
03b9a7
 
03b9a7
     debug("cmgr: decoded time: '%s' (now: %d)\n", time_str, (int) now);
03b9a7
 
03b9a7
+    char *user_name;
03b9a7
     if ((user_name = strtok(NULL, "|")) == NULL) {
03b9a7
         xfree(buf);
03b9a7
         return;
03b9a7
     }
03b9a7
+    rfc1738_unescape(user_name);
03b9a7
 
03b9a7
     debug("cmgr: decoded uname: '%s'\n", user_name);
03b9a7
 
03b9a7
+    char *passwd;
03b9a7
     if ((passwd = strtok(NULL, "|")) == NULL) {
03b9a7
         xfree(buf);
03b9a7
         return;
03b9a7
     }
03b9a7
+    rfc1738_unescape(passwd);
03b9a7
 
03b9a7
     debug("cmgr: decoded passwd: '%s'\n", passwd);
03b9a7