簡體   English   中英

是否可以使用過期的密碼對Active Directory用戶進行身份驗證?

[英]Is it possible to authenticate an Active Directory User with an Expired password?

我有一個使用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

有沒有解決的辦法?

謝謝你的幫助。

據我了解,如果要求用戶在下次登錄時更改其密碼(用戶的密碼已過期),Active Directory將不允許我們使用LDAP來確定其密碼是否無效。 這是因為用戶必須更改密碼。 我在這里找到以下解決方案:

若要確定密碼是否已過期,可以調用Win32:LogonUser(),然后檢查Windows錯誤代碼中的以下2個常量:

ERROR_PASSWORD_MUST_CHANGE = 1907
ERROR_PASSWORD_EXPIRED = 1330

我有一個非官方的答復 作為管理員,您將pwdLastSet設置為0的用戶將pwdLastSet設置為-1。這樣做的作用是使Active Directory相信密碼已被更改。 然后,使用AuthADuser方法檢查密碼。 然后,您將pwdLastSet放回0。我沒有對其進行測試,只是想象一下,從安全角度來看,它並不是那么干凈(在法國,我們稱之為“ bricolage ”)。

告訴我是否可行?

我希望它會有所幫助;

J.P

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM