gpt4 book ai didi

java - 使用 JNA 的 LogonUser 导致 "unknown user name or bad password"

转载 作者:行者123 更新时间:2023-11-30 05:47:43 29 4
gpt4 key购买 nike

我尝试实现一种功能来使用某些凭据执行某些应用程序。为此,我检查是否可以使用凭据登录。

import com.sun.jna.LastErrorException;
import com.sun.jna.platform.win32.Advapi32;
import com.sun.jna.platform.win32.Kernel32;
import com.sun.jna.platform.win32.WinBase;
import com.sun.jna.platform.win32.WinNT;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class TestHarness {

public static void main(String[] args) throws UnknownHostException {

WinNT.HANDLEByReference phUser = new WinNT.HANDLEByReference();
System.out.println(InetAddress.getLocalHost().getHostName());
if (!Advapi32.INSTANCE.LogonUser("de313e", ".",
"password", WinBase.LOGON32_LOGON_NETWORK, WinBase.LOGON32_PROVIDER_DEFAULT, phUser)) {
throw new LastErrorException(Kernel32.INSTANCE.GetLastError());
}
}
}

不幸的是,这给了我

com.sun.jna.LastErrorException: GetLastError() returned 1326

提供的用户名是我当前的用户名。为什么这不起作用?

我在 Windows 10 上运行它。我的密码包含一些特殊字符,例如 !&。用户的名称为:

enter image description here

最佳答案

LogonUser 的文档参数 lpszDomain 的状态:

A pointer to a null-terminated string that specifies the name of the domain or server whose account database contains the lpszUsername account. If this parameter is NULL, the user name must be specified in UPN format. If this parameter is ".", the function validates the account by using only the local account database.

由于您正在使用"."您仅针对本地用户数据库进行验证。这适用于 sysadmin本地计算机上的帐户 (NB3DE2730054)。但是,您正在尝试验证域用户 de313e因此您必须指定域 MASTDOM .

作为替代方案,您可以将域设置为 null并包含用户的域:de313e@MASTDOM 。或者,正如您在评论中指出的,如果您使用 logonType LOGON32_LOGON_NEW_CREDENTIALS和登录提供商LOGON32_PROVIDER_WINNT50 "."会起作用的。

关于java - 使用 JNA 的 LogonUser 导致 "unknown user name or bad password",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54567837/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com