Click to See Complete Forum and Search --> : How to change pwd in active dir using ASP?


chandru2211
02-20-2008, 12:16 AM
Hi,

I am creating a web based application to monitor & administer the ADS using ASP. I have tried the code given below which was suppose to change the password of a user in ADS. It displays the error msg "Unable to uthenticate. Password or Username incorrect". Can any one help me ??

Code follows:
Sub change_password()
on Error Resume Next
Dim oldpass,newpass,confirmpass
oldpass=session("password")
newpass=Request.form("txt_new")
confirmpass=Request.form("txt_confirm")


If newpass=confirmpass then
strusername="LDAP://cn="& session("userid")&","&"cn=Users,dc=corp,dc=mydomain,dc=com"
set objNamespace = GetObject("LDAP://corp.mydomain.com")
set objUser = objNamespace.OpenDSObject(strusername, session("userid"), session("password"), 0)

If Err=0 Then
objUser.ChangePassword CStr(Request.Form("OldPassword")), CStr(Request.Form("NewPassword1"))
If Err=0 Then
Response.Write "Password has been changed."
Else
Response.Write "Error: the Password has not been changed."
End If
Else
Response.Write "Unable to authenticate. Password or Username incorrect."
End If
Else
Response.Write "The two new passwords do not match. Please try again."
End If



End Sub

yamaharuss
02-20-2008, 06:57 AM
For one thing, your IF statements are all screwy.

If Err=0 Then
objUser.ChangePassword CStr(Request.Form("OldPassword")),CStr(Request.Form("NewPassword1"))

....' THE CODE BLOCK BELOW IS USELESS - IT DOES NOTHING
...............If Err=0 Then
...............Response.Write "Password has been changed."
...............Else
...............Response.Write "Error: the Password has not been changed."
...............End If


Else
Response.Write "Unable to authenticate. Password or Username incorrect."
End If

' THIS ENDS IT HERE- THE REST BELOW IS ERROR



Else ' WHERE IS THE BEGINNING "IF" FOR THIS "ELSE"?
Response.Write "The two new passwords do not match. Please try again."
End If