Password changer (ASP)

This code can be found in Chapter 28 of Active Directory, 3rd Edition

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the ASP code from this site.

<HTML>
<!--
' From the book "Active Directory, Third Edition" 
' ISBN: 0-596-10173-2
-->
<HTML>
<HEAD>
<TITLE>Simple Password Changer</TITLE>
</HEAD>
   
<BODY>
<%
  On Error Resume Next
  If Request.Form("SetPass") = "Change Password!" Then
    If Request.Form("NewPassword1") = Request.Form("NewPassword2") Then
   
      strUsername = "LDAP:// " & Request.Form("Name")
      Set objNamespace = GetObject("LDAP: ")
      'Attempt to authenticate to the user object in the tree using 
      'the username and the current password
      Set objUser = objNamespace.OpenDSObject(strUsername, _
        Request.Form("Name"), Request.Form("OldPassword"), 0)
      If Err=0 Then
    
        'Attempt to change the password
        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 If
%>
<FORM ACTION="psw_changer1.asp" METHOD=POST>
   
  <P>Name <BR><INPUT 
    NAME="Name"
    TYPE=TEXT
    VALUE="cn=xxxxx,cn=Users,dc=mycorp,dc=com"
    SIZE="60">
   
  <P>Old Password<BR><INPUT 
    TYPE="PASSWORD"
    NAME="OldPassword">
   
  <P>New Password<BR><INPUT 
    TYPE="PASSWORD"
    NAME="NewPassword1">
  <P>Confirm Password<BR><INPUT 
    TYPE="PASSWORD"
    NAME="NewPassword2">
   
  <P><INPUT TYPE="SUBMIT" NAME="SetPass" VALUE="Change Password!">
  <INPUT TYPE="RESET" VALUE="Reset">
</FORM>
</BODY>
</HTML>

This code has been viewed 6202 times.

New from the creators of TechTasks.com: StatSheet.com