--- qt-everywhere-commercial-src-4.7.1/src/network/kernel/qauthenticator.cpp.orig	2010-11-05 18:53:28.000000000 -0700
+++ qt-everywhere-commercial-src-4.7.1/src/network/kernel/qauthenticator.cpp	2010-11-19 14:32:17.000000000 -0800
@@ -165,8 +165,9 @@
     if (d == other.d)
         return *this;
     detach();
-    d->user = other.d->user;
+    d->origUser = other.d->origUser;
     d->password = other.d->password;
+    d->updateCredentials();
     return *this;
 }
 
@@ -206,49 +207,9 @@
 void QAuthenticator::setUser(const QString &user)
 {
     detach();
-    int separatorPosn = 0;
 
-    switch(d->method) {
-    case QAuthenticatorPrivate::DigestMd5:
-        if((separatorPosn = user.indexOf(QLatin1String("\\"))) != -1) {
-            //domain name is present
-	    d->userDomain.clear();
-            d->realm = user.left(separatorPosn);
-            d->user = user.mid(separatorPosn + 1);
-        } else if((separatorPosn = user.indexOf(QLatin1String("@"))) != -1) {
-            //domain name is present
-	    d->userDomain.clear();
-            d->realm = user.mid(separatorPosn + 1);
-            d->user = user.left(separatorPosn);
-        } else {
-            d->user = user;
-            d->realm.clear();
-            d->userDomain.clear();
-        }
-        break;
-
-    case QAuthenticatorPrivate::Ntlm:
-        if((separatorPosn = user.indexOf(QLatin1String("\\"))) != -1) {
-            //domain name is present
-            d->realm.clear();
-            d->userDomain = user.left(separatorPosn);
-            d->user = user.mid(separatorPosn + 1);
-        } else if((separatorPosn = user.indexOf(QLatin1String("@"))) != -1) {
-            //domain name is present
-            d->realm.clear();
-            d->userDomain = user.left(separatorPosn);
-            d->user = user.left(separatorPosn);
-        } else {
-            d->user = user;
-	    d->realm.clear();
-            d->userDomain.clear();
-        }
-        break;
-    // For other auth mechanisms, domain name will be part of username
-    default:
-        d->user = user;
-        break;
-    }
+    d->origUser = user;
+    d->updateCredentials();
 }
 
 /*!
@@ -399,6 +360,9 @@
         }
     }
 
+    // method has been changed, update realm/domain if required
+    updateCredentials();
+
     challenge = headerVal.trimmed();
     QHash<QByteArray, QByteArray> options = parseDigestAuthenticationChallenge(challenge);
 
@@ -428,6 +392,53 @@
     }
 }
 
+void QAuthenticatorPrivate::updateCredentials()
+{
+    int separatorPosn = 0;
+
+    switch(method) {
+    case QAuthenticatorPrivate::DigestMd5:
+        if((separatorPosn = origUser.indexOf(QLatin1String("\\"))) != -1) {
+            //domain name is present
+	    userDomain.clear();
+            realm = origUser.left(separatorPosn);
+            user = origUser.mid(separatorPosn + 1);
+        } else if((separatorPosn = origUser.indexOf(QLatin1String("@"))) != -1) {
+            //domain name is present
+	    userDomain.clear();
+            realm = origUser.mid(separatorPosn + 1);
+            user = origUser.left(separatorPosn);
+        } else {
+            user = origUser;
+            realm.clear();
+            userDomain.clear();
+        }
+        break;
+
+    case QAuthenticatorPrivate::Ntlm:
+        if((separatorPosn = origUser.indexOf(QLatin1String("\\"))) != -1) {
+            //domain name is present
+            realm.clear();
+            userDomain = origUser.left(separatorPosn);
+            user = origUser.mid(separatorPosn + 1);
+        } else if((separatorPosn = origUser.indexOf(QLatin1String("@"))) != -1) {
+            //domain name is present
+            realm.clear();
+            userDomain = origUser.left(separatorPosn);
+            user = origUser.left(separatorPosn);
+        } else {
+            user = origUser;
+	    realm.clear();
+            userDomain.clear();
+        }
+        break;
+    default:
+        user = origUser;
+        break;
+    }
+}
+
+
 QByteArray QAuthenticatorPrivate::calculateResponse(const QByteArray &requestMethod, const QByteArray &path)
 {
     QByteArray response;
@@ -1333,7 +1344,6 @@
     if (data.size() < QNtlmPhase2BlockBase::Size)
         return false;
 
-
     QDataStream ds(data);
     ds.setByteOrder(QDataStream::LittleEndian);
     if (ds.readRawData(ch.magic, 8) < 8)
--- qt-everywhere-commercial-src-4.7.1/src/network/kernel/qauthenticator_p.h.orig	2010-11-05 18:53:28.000000000 -0700
+++ qt-everywhere-commercial-src-4.7.1/src/network/kernel/qauthenticator_p.h	2010-11-19 14:23:43.000000000 -0800
@@ -76,6 +76,9 @@
     Method method;
     QString realm;
     QByteArray challenge;
+    // original user with domain part
+    // we need to keep it in order to re-parse if auth method is changed
+    QString origUser;
 
     enum Phase {
         Start,
@@ -105,6 +108,7 @@
     void parseHttpResponse(const QHttpResponseHeader &, bool isProxy);
 #endif
     void parseHttpResponse(const QList<QPair<QByteArray, QByteArray> >&, bool isProxy);
+    void updateCredentials();
 
 };
 
