Qt 中的 NTLMv2 身份验证 [英] NTLMv2 authentication in Qt

查看:27
本文介绍了Qt 中的 NTLMv2 身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

QNetworkAccessManager 发出

QNetworkAccessManager emits the

authenticationRequired (QNetworkReply*, QAuthenticator*)

需要身份验证时发出信号.这可用于基本身份验证.

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

但是如何制作一个 Qt 程序来与服务器进行 NTLM 身份验证?我在任何地方都找不到这方面的例子.

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

推荐答案

我无法让它在 Qt 4.8 上工作,但在 Qt 5.1 上它有点工作.在这种情况下,QAuthenticator 工作得非常糟糕.如果要在处理 authenticationRequired 信号的槽中手动设置用户名和密码:

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");
} 

但是,如果要使用当前的Windows用户登录,则需要将用户名设置为空字符串:

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("");
} 

注意:即使授予 Windows 用户访问权限,此插槽也将被调用 4 次.如果用户应该提供凭据,这尤其令人沮丧.此外,QAuthenticator 不提供任何公共方法来确定实际使用的身份验证方法.

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.

这篇关于Qt 中的 NTLMv2 身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆