我正在开发一个网站,它将对用户进行身份验证并将旧密码更改为新密码。
我正在使用 WinNT 字符串连接并设置密码,没有旧密码检查,可以正常工作。
我的代码如下:
'actual setting password
Dim entryD As New DirectoryEntry("WinNT://" + Environment.MachineName + ",computer")
Dim NewUser As DirectoryEntry = entryD.Children.Find(username, "user")
Dim nativeobject As Object = NewUser.NativeObject
NewUser.Invoke("SetPassword", New Object() {strPassNew})
NewUser.CommitChanges()
'setting password ends
这工作正常,但验证码不起作用。
如下:
'authentication starts
Dim adsiPath As String
adsiPath = String.Format("WinNT://{0}/{1},user", domain, username)
Dim userEntry = New DirectoryEntry(adsiPath, username, password, AuthenticationTypes.Secure)
'Dim nativeobject1 As Object = userEntry.NativeObject
Dim newobj As ActiveDs.IADsUser = userEntry.NativeObject
authent = True
'authentication ends
这进行了身份验证,但抛出的异常是:
logon failure: unknown username or bad password
第一次,但如果我再次这样做,错误是:
"Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed. Disconnect all previous connections to the server or shared resource and try again. "
这是我不想发生的……我不想使用 LDAP,我想要一个解决方案,以验证旧密码。请帮忙?
最佳答案
我的代码中有这个错误,要求将域用户添加到系统的本地管理员组。在第一次尝试后测试代码时,我曾经遇到“与服务器的多个连接......”错误,然后如果稍后(一个小时左右)尝试代码代码,它工作正常。通过各种形式搜索后,我知道我们可以看到用户使用
登录到计算机NET SESSION /LIST
远程系统 cmd 中的命令,看起来当我们使用 WinNT 提供程序时,它实际上在远程计算机上创建了一个空闲超时的用户 session (可能存在其他程序正在创建 session 的情况),当您尝试连接时会发生冲突第二次。所以我尝试删除之前的 session
NET SESSION \\RequestingComputerName /DELETE
然后我没有报错。如果这不能解决问题,那么最后的办法就是重新启动系统。
关于vb.net - 使用 WinNT 字符串连接更改用户密码时出错(并验证当前密码),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10257459/