PDA

View Full Version : Basic Authentication



lyhoanghai
1st September 2010, 09:11
Hello,

I'm using QAccessNetworkManager to download data from a URL.
In order to provide Basic Authentication, I connect signal authenticationRequired() which is called everytime the server challenge the client.

My applications cache username & password (even if the application exits, his password is stored and is reused) and slot for authenticationRequired() just returns the cache of username & password.


void authenticationRequired (QNetworkReply * reply, QAuthenticator *authenticator) {
authenticator->setUser(getCacheUsername());
authenticator->setPassword(getCachePassword());
}


Suppose that password is incorrect, then the slot always returns incorrect data and server continue to challenge client again and authenticationRequired() continue to returns incorrect credentials and the server challenge again.... that will happens for ever and application is loop !

I think my problem is quite typical for all application which cache password of user. What is the best practice to solve this problem?

Thank you very much

Hai

wysota
1st September 2010, 09:43
Count the times the auth was incorrect and after a number of failures just re-ask the user or fail gracefully.

frankiefrank
16th May 2011, 12:00
I have a similar issue. Wysota, thanks for your solution offer.

I use one QNetworkAccessManager for multiple download calls. I can use the signal's reply object to trace my original request, but is there any other Qt way to know that the specific reply failed authentication?

I see both the QNetworkRequest::HttpStatusCodeAttribute and error() return 0...