2011-04-21 20 views
0

我正在使用基於Web的「忘記密碼」重置AD密碼。好吧,我可以解鎖用戶,但不能更改密碼。在.NET中忘記Active Directory密碼腳本

這裏是我的功能:

Private Function ChangeLocalUserPassword(ByVal User As String, ByVal Pass As String) As Boolean 
    Dim pinger As New Net.NetworkInformation.Ping 
    Dim usr As DirectoryEntry 
    _de = GetDirectoryEntry() 

    If _de Is Nothing Then 
     'couldn't connect or find account 
     MsgBox("_de is Nothing") 
     Return False 
    End If 
    Try 
     usr = _de.Children.Find("CN=" & User, "User") 
    Catch ex As Exception 
     MsgBox("User could not be found!") 
     Return False 
    End Try 
    Try 
     usr.Invoke("SetPassword", Pass) 
     usr.CommitChanges() 
     usr.Properties("LockOutTime").Value = 0 
     usr.CommitChanges() 
    Catch ex As Exception 
     MsgBox("Error is " & ex.Message) 
     Return False 
    End Try 

End Function 

這裏是我的GetDirectoryEntry功能:

Private Function GetDirectoryEntry() As DirectoryEntry 
     Dim dirEntry As DirectoryEntry = New DirectoryEntry() 
     dirEntry.Path = "LDAP://<SERVER>/ou=<OU>,dc=<DOMAIN>" 
     dirEntry.Username = "<DOMAIN>\Administrator"   
     dirEntry.Password = "<PASSWORD>" 
     Return dirEntry 
    End Function 

A面的問題 - 任何人都建議我,我怎樣才能解決硬編碼的管理員用戶頁?將創建一個具有幾個管理員權限的IUSR工作?

任何幫助表示讚賞!

+0

當您嘗試設置密碼時,您是否遇到異常? – guanome 2011-04-26 14:05:46

+0

我沒有得到異常。 – NeerPatel 2011-04-26 15:02:36

+0

那麼,它只是默默地失敗了? – guanome 2011-04-26 18:41:40

回答

0

重置密碼PwdLastSet是關鍵屬性。如果PwdLastSet的值設置爲零,則用戶在登錄agin(see article)時必須更改其密碼。

對於你方的問題:

在活動目錄中創建一個新用戶。

在目標組織單位中,或直接在域容器上,您只需將重新設置密碼的權限委託給新用戶。所以你的應用程序只操作一個只允許重置密碼的用戶和密碼。

+0

我只能這樣做,如果我想強制他們在下次登錄時重置密碼,對嗎? – NeerPatel 2011-04-25 22:48:03

+0

是的,對我來說,這是一個遺忘的密碼服務必須做的。 – JPBlanc 2011-04-26 03:14:52