这在VB.NET中是否可行?
由于
答案 0 :(得分:3)
此函数将根据活动目录验证用户名和密码。您将需要导入System.DirectoryServices命名空间。您还需要在“domain”var中指定域的LDAP路径,例如“dc = mydomain,dc = com”。
另外,看一下My.User。*的东西。
Private Function Authenticate(userName As String, password As String, domain As String) As Boolean
Dim authentic As Boolean = False
Try
Dim entry As New DirectoryEntry("LDAP://" & domain, userName, password)
Dim nativeObject As Object = entry.NativeObject
authentic = True
Catch generatedExceptionName As DirectoryServicesCOMException
End Try
Return authentic
End Function
答案 1 :(得分:0)
这听起来好像是使用Windows身份验证或类似功能完成的。验证通常针对Active Directory进行。
您也可以自动记录使用它的人,只要他们登录Windows并且(我相信)您正在运行IIS服务器或类似服务器。
答案 2 :(得分:0)
首先,您必须添加引用:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.DirectoryServices.dll
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.DirectoryServices.AccountManagement.dll
您必须导入:
Imports System.DirectoryServices.AccountManagement
验证功能
Private Function ValidateUsername(ByVal Domain As String, ByVal Username As String, ByVal Password As String) As Boolean
Dim context As PrincipalContext = New PrincipalContext(ContextType.Domain, Domain)
Try
If context.ValidateCredentials(Username, Password) = True Then
Return True
End If
Catch ex As Exception
Return False
End Try
End Function
设置自动登录的功能:
Public Shared Sub EnableDomainAutologon(ByVal Domain As String, ByVal Username As String, ByVal Password As String)
Try
Dim reg As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", True)
reg.SetValue("AutoAdminLogon", "1", RegistryValueKind.String)
reg.SetValue("DefaultUserName", Username, RegistryValueKind.String)
reg.SetValue("DefaultPassword", Password, RegistryValueKind.String)
reg.SetValue("DefaultDomainName", Domain, RegistryValueKind.String)
reg.Close()
MsgBox("The autologon feature has been enabled!", MsgBoxStyle.Information, "Autologon Enabled")
Catch ex As Exception
MsgBox(ex.ToString, MsgBoxStyle.Critical, "Error")
End Try
End Sub
要设置注册表,您需要管理员权限,因此必须在app.manifest中将级别设置为“ requireAdministrator”:
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
验证用户名和密码的功能可能需要一段时间。