PasswordChange


D

Dave

Hi,
I am trying to make self-service password change(reset) page. below is my
code to change password:

Caller section

Dim ob As New LdapAuthentication

Try

ob.changeOldPassword(txtUsername.Text, txtOldPassword.Text,
txtNewPassword1.Text) 'path is LDAP://DC=my,DC=local ** I got error here **

End If

Catch ex As Exception

Response.Write(ex.Message)

End Try



Callee section

Public Function changeOldPassword(ByVal username As String, ByVal
oldpassword As String, ByVal newpassword As String) As Boolean

Try

Const ADS_UF_ACCOUNTDISABLE As Integer = &H2

Dim user As New DirectoryEntry()

Dim domain_username = "domain\" & username

Dim entry As DirectoryEntry = New DirectoryEntry(_path, domain_username,
oldpassword)

Dim bindCheck As Object = entry.NativeObject

Dim search As New DirectorySearcher(entry)

search.Filter = "(sAMAccountName=" & username & ")"

user = New DirectoryEntry(search.FindOne.GetDirectoryEntry.Path)

user.AuthenticationType = AuthenticationTypes.Secure Or
AuthenticationTypes.Sealing

'change password

user.Invoke("ChangePassword", New Object() {oldpassword, newpassword})

Dim flags As Integer = user.Properties("userAccountControl").Value

user.Properties("userAccountControl").Value = flags And Not
ADS_UF_ACCOUNTDISABLE

user.CommitChanges()

Catch ex As Exception

Throw New Exception("ERROR::" & ex.InnerException.InnerException.Message)

End Try

End Function



Problem:

Firstly I got "password policy" error but my new password was within the
policy rule, I can also check the validity of users against AD.

Now I am getting error on (as pointed above ** ....**) "Object reference
not set to an instance of an object. "

Is there anything i overlooked or any mistakes? Anyone any suggestion?

Thanks.
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top