NTLMv2 authentication in Qt

2019-06-14 10:07发布

QNetworkAccessManager emits the

authenticationRequired (QNetworkReply*, QAuthenticator*)

signal when authentication is required. This can be used for basic authentication.

But how to make a Qt program to do NTLM authentication with the server ? I couldnt find examples for this anywhere.

标签: qt qt5
1条回答
做自己的国王
2楼-- · 2019-06-14 10:29

I couldn't get this to work on Qt 4.8, but on Qt 5.1 it kind of works. The QAuthenticator works really badly in this case. If you want to set the username and password manually in the slot that processes the authenticationRequired signal:

onAuthenticationRequired (QNetworkReply*, QAuthenticator* auth)
{
    auth->setUser("username");
    auth->setPassword("password");
} 

However, if you want to use the current Windows user login, you need to set the username as an empty string:

onAuthenticationRequired (QNetworkReply*, QAuthenticator* auth)
{
    auth->setUser("");
} 

NOTE: This slot will be called 4 times even when the Windows user is granted access. This is especially frustrating if the user is supposed to provide the credentials. Additionally the QAuthenticator does not provide any public methods to figure out which authentication method is actually being used.

查看更多
登录 后发表回答