Q. How can I create a Web page where users can change their passwords?

John Savill

April 25, 2004

2 Min Read
ITPro Today logo in a gray background | ITPro Today

A. You can write an Active Server Pages (ASP) script that creates a password-change Web page. ASP gives you complete access to Microsoft Active Directory Service Interfaces (ADSI), which lets you perform a variety of functions, such as changing passwords or creating accounts. When you write such a script, you must consider factors such as the user account under which the script will run and the permissions you want to use when the script runs. The basic ADSI command to change a user's password is

set usr = GetObject("LDAP://CN=John
Savill,CN=Users,DC=savilltech,DC=com")
usr.put "userPassword", NewPassword

The first line (shown as two lines because of space constraints) assigns a handle to user John Savill in domain savilltech.com. The next line puts the text NewPassword into the userPassword attribute.

I've written a short ASP script called Changepass.asp that prompts the user to enter a username and password (remember to change the domain from savilltech.com to your domain). Changepass.asp, which is available at code , is listed below.

<%strUserCN = request.form("cn")strNewPassword = request.form("newpass")strPassVerify = request.form("passverify")if strUserCN="" then    response.write "<html><head><title>Change Password</title></head><body>"    response.write "<center><h1>Web Password Reset</h1></center>"    response.write "<hr><br><br><form method=post action=changepass.asp><table>"    response.write "<tr><td>CN: </td><td><input type=text name=cn></td><tr>"    response.write "<tr><td>New Password: </td><td><input type=password name=newpass></td></tr>"    response.write "<tr><td>Verify Password: </td><td><input type=password name=passverify></td></tr>"    response.write "<tr><td colspan=2 align=center><input type=submit value='Reset Password'></td></tr>"    response.write "</table></body></html>"    response.endelseif strNewPassword = strPassVerify thenset usr = GetObject("LDAP://CN=" & strUserCN & ",CN=Users,DC=savilltech,DC=com")usr.put "userPassword", strNewPasswordresponse.write "<html><head><title>Results</title></head><center><h1>Update Results</h1></center><hr><br><br>"response.write strUserCN & ": password was successfully updated"response.endelse    response.write "<html><head><title>Error!</title></head><body>"    response.write "<center><h1>An Error Has Occurred!</h1></center>"    response.write "<hr><br><br>"    response.write "The password and confirmation do not match. Please go back and try again."    response.endend ifend if%>

Windows Server 2003 provides its own Web pages for password changes, which I discuss in the FAQ "Does Windows Server 2003 provide a way to let users change their passwords remotely on the Web?". However, you might find the sample ASP script useful for creating password-change interfaces on your own Web pages or sites.

About the Author

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like