【问题标题】:Is it possible to authenticate an Active Directory User with an Expired password?是否可以使用过期密码对 Active Directory 用户进行身份验证?
【发布时间】:2011-04-07 12:02:06
【问题描述】:

我有一个使用 AD 对用户进行身份验证的 Web 表单。我希望能够对密码过期的用户进行身份验证,并在身份验证后将他们重定向到密码更改页面。

例如,如果网站管理员重置用户密码,我使用下面的方法,让用户在下次登录时重置密码。

Public Shared Sub ForceUserToResetPassword(ByVal LDAP_URI As String, ByVal UserName As String, ByVal       Auth_UserName As String, ByVal Auth_Password As String)
    Dim LDAPEntry As DirectoryEntry = Nothing
    Try
        LDAPEntry = New DirectoryEntry(LDAP_URI, Auth_UserName, Auth_Password, AuthenticationTypes.Secure)
        Dim LDAPSearch As New DirectorySearcher()
        LDAPSearch.SearchRoot = LDAPEntry
        LDAPSearch.Filter = "(&(objectClass=user)(sAMAccountName=" & UserName & "))"


        LDAPSearch.SearchScope = SearchScope.Subtree
        Dim results As SearchResult = LDAPSearch.FindOne()
        If Not (results Is Nothing) Then
            LDAPEntry = New DirectoryEntry(results.Path, Auth_UserName, Auth_Password, AuthenticationTypes.Secure)
        End If

        LDAPAccess.SetProperty(LDAPEntry, "pwdLastSet", 0)
        LDAPEntry.CommitChanges()

    Catch ex As Exception

    End Try
End Sub

这样做会使用户的密码过期。如果用户尝试使用新密码登录,则身份验证失败并显示“登录失败:未知用户名或密码错误”。

这是我的授权。方法:

Public Shared Function AuthADuser(ByVal LDAP_URI As String, ByVal UserName As String, ByVal password As String, ByVal Auth_UserName As String, ByVal Auth_Password As String) As Boolean
    Dim IsAuth As Boolean = False
    Dim LDAPEntry As DirectoryEntry = Nothing
    Try
        LDAPEntry = New DirectoryEntry(LDAP_URI, UserName, password, AuthenticationTypes.Secure)
        Dim tmp As [Object] = LDAPEntry.NativeObject
        IsAuth = True
    Catch ex As Exception
        LDAPEntry.Dispose()
        If ex.Message.StartsWith("The server is not operational") Then
            IsAuth = False
        ElseIf ex.Message.StartsWith("Logon failure:") Then
            Throw New ApplicationException("The Username and password combination are not valid to enter the system.")
        End If
    Finally
        LDAPEntry.Close()
    End Try
    Return IsAuth
End Function

有没有办法解决这个问题?

感谢您的帮助。

【问题讨论】:

  • 这似乎是白费力气。如果他们的密码已过期并且需要更改,那么在他们打开 Web 浏览器并访问您的 Intranet 站点之前很久,登录到该域就会提示更改密码。

标签: vb.net active-directory


【解决方案1】:

据我了解,如果用户需要在下次登录时更改其密码(用户密码已过期),Active-Directory 将不允许我们使用 LDAP 来确定他的密码是否无效。这是因为用户必须更改密码。我找到here以下解决方案:

要判断密码是否过期,可以调用Win32:LogonUser(),查看windows错误码是否有以下2个常量:

ERROR_PASSWORD_MUST_CHANGE = 1907
ERROR_PASSWORD_EXPIRED = 1330

我有一个非官方的答案。作为管理员,您将pwdLastSet 设置为0 的用户的pwdLastSet 设置为-1。这样做的效果是使Active-Directory 相信密码刚刚被更改。然后,您使用AuthADuser 方法检查密码。然后你将pwdLastSet 放回 0。我没有测试它,只是想象一下,从安全角度来看,它并不是那么干净(在法国,我们称之为“bricolage”)。

告诉我它是否有效?

希望对你有帮助;

日本

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-25
    • 1970-01-01
    • 2011-12-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多