Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  Advanced Search 


January 2001

Changing Passwords over the Web


RSS
Subscribe to Windows IT Pro | See More Internet Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

Download the Code Here

ADSI helps you give users an easy-to-use Web interface for changing their passwords

Locally logged-on users can easily change their password through the Windows interface. When you're using Integrated Windows, Windows NT Challenge/Response, or Digest authentication, a user must log on to a system that supports Microsoft Internet Explorer (IE) and the authentication method. The user can use standard Windows utilities to change a password directly through the Windows interface during the current logon session. Users who are disconnected from the network part of the time can change their passwords during their next logon session.

However, when you're using Basic authentication or you need to implement a Web-browser-based change-password interface for users of an OS authentication method, you have no easy way for users to change their password. In these situations, Microsoft Active Directory Service Interfaces (ADSI) and some straightforward code let you give users an interface for password change.

Authentication Methods
Before you tackle password changes, you need to understand the authentication methods that Windows 2000 and NT 4.0 use and select the one that is appropriate for your situation. NT 4.0 can use Anonymous access, which lets anyone use a Web application or Web site. Microsoft IIS automatically uses the IUSR_MachineName account to log an Anonymous user on to the server. If you turn off Anonymous access, NT 4.0 can use Basic authentication, which prompts the user for a username and password when the user first visits a site or application. Then the OS verifies the username and password against the local user account or domain database.

Win2K and NT 4.0 can use another authentication option, which goes by a different name in each system: Integrated Windows security in Win2K and NT Challenge/Response in NT 4.0. Both mechanisms operate similarly to Basic authentication, but instead of forcing the user to enter a username and password, Integrated Windows security and NT Challenge/Response take the username and password from the OS. Then, IE uses the Web server's security database (e.g., the SAM, Active Directory—AD) to verify the username and password.

Win2K supports Digest authentication, which works only with Win2K domain controllers (DCs). Digest authentication takes the username and password from the credentials that the user supplied to the browser and verifies them against the user account database that the Web server uses.

You can also authenticate users against a database table, effectively creating your own authentication system. However, if you use this method, you lose Win2K or NT 4.0 security features that are available if the OS authenticates users. For example, you can't use ACLs or other OS security features that require authenticated users.

Choose an authentication method that fits your security goals. If you need file security, use Basic authentication, Integrated Windows security, NT Challenge/ Response, or—in Win2K—Digest authentication. If you just need application security, create an authentication system.

Using the IADsUser Interface
ADSI gives you a set of directory service interfaces for managing network resources, and you can use the ADSI IADsUser interface and script to change a user's password. I created two Active Server Pages (ASP) pages that demonstrate this procedure. Figure 1 shows the first page, ChangePasswordEntry.asp, and Listing 1 shows the script for the page.

ChangePasswordEntry.asp is an HTML file that gathers three crucial pieces of information for changing a user's password: username, existing password, and new password. After a user enters the information and clicks Submit, the script passes control to Change Password1.asp. This file contains the code, which Listing 2 shows, that actually changes the user's password.

The code in Listing 2 works in Win2K and NT 4.0 for usernames that are stored locally and aren't part of a domain or AD. Callout A in Listing 2 dimensions (i.e., creates) several variables that Change Password1.asp uses. Dimensioning makes code more readable for developers. You must use Option Explicit in code to force the dimensioning of all variables.

The code in Listing 2's callout B uses Xname and password values from ChangePasswordEntry.asp and place these values in the corresponding variables that callout A created. The If statement at callout B checks whether the sUser variable is blank. If it's blank, the code sends control back to ChangePasswordEntry.asp.

The code at callout C starts Change Password1.asp's real work. When you use ADSI, you must communicate with an ADSI provider that manages the resource you're connecting to. ChangePassword1 .asp uses the WinNT provider, which also works with Win2K when the Web server is using local user accounts. Callout C's first line builds the connection string and stores it in the sConnectString variable to begin the process of connecting to the WinNT provider. The connection string consists of the provider name (WinNT), separators (://), the computer name (bigboat), and a closing separator (/). Then callout C appends the username and ",user" to the string. The username represents the user object of the WinNT provider. The user object represents a user account.

After callout C's sConnectString statement builds the connection string, the Response.Write statement displays the string by sending it to the HTTP stream. Response.Write statements are great for debugging. After you've tested the code, you can precede them with one quotation mark (') so that they won't be executed. The Set oUser statement at callout C binds the oUser variable to an instance of the user object that represents the user specified in the connection string.

The two Response.Write statements that follow callout C help you debug the sample code because they let you inspect the username and password that Basic authentication provided to the server. They use the ServerVariables collection of the ASP Request object. The first line uses the LOGON_USER variable, which represents the currently logged-on user. You could also use the REMOTE_USER variable to return the user account. The second line returns the user's password from the AUTH_ PASSWORD variable if the user is logged on with Basic authentication.

The line that changes the password is

oUser.ChangePassword sPassword, sNewPassword

at callout D. The first parameter to ChangePassword is the user's current password (sPassword). The second parameter is the user's new password (sNewPassword). After the script has finished running, the new password will take effect.

   Previous  [1]  2  Next 


Reader Comments
You can easily add a few lines of code to make the user re-type the passwords to avoid typo's being entered:<br><br>

In the ChangePasswordEntry.ASP file add another entry to ask the user to retype their new password:<br><br>
&lt;TD&gt; Retype New Password &lt;/TD&gt;<br>
&lt;TD&gt;&lt;INPUT id=txtReNewPassword name=txtReNewPassword<br>
type=password&gt;&lt;/code&gt;<br><br>

In the ChangePassword1.ASP add in the new variable and then compare the two, and if they don't match I send the user to another page that lets them know what was wrong:<br><br>

sUser = request("txtUserName")
sPassword = request("txtPassword")
sNewPassword = request("txtNewPassword")
rNewPassword = request ("txtReNewPassword")
if sUser = "" then Response.Redirect "ChangePasswordEntry.asp"
if sNewPassword &lt;&gt; rNewPassword then Response.Redirect "Mismatch.asp"<br><br>

My mismatch.asp file is very simple:<br><br>
&lt;HTML&gt;<br>
&lt;HEAD&gt;<br>
&lt;TITLE&gt;Password Mismatch.&lt;/TITLE&gt;<br>
&lt;/HEAD&gt;<br>
&lt;BODY&gt;<br>
&lt;P&gt;The New Password was not retyped correctly. Hit the Back button on your browser and try again.&lt;/P&gt;<br>
&lt;/BODY&gt;<br>
&lt;/HTML&gt;<br>

Greg Onstot January 03, 2001


I was TRYING to work with this code, but I came across, the line of code sConnectString = "WinNT://bigboat/" & sUser & ",user" and a discription of what the WinNT should be is "WinNT provider"? Im confused on what that is, so if someone could please help...either pointing me in the right direction or telling me what it is?
Thanks.

Anna January 26, 2001


Anna,
sConnectString = "WinNT://bigboat/" & sUser & ",user"

WinNT - designates you are using a Window NT Domain (not a local machine account, or AD)
//bigboat/ - Substitute the name of your NT Domain for the name bigboat
sUser & ",user" - this just designates that you are working with user data

Does this answer your question?

Greg January 31, 2001


I'm having a hard time making this work on my stand alone Web server using NT 4.0. I using the ASP file is pulling the interface up but I can't get it to change the account locally. Please help me if you can. Thanks..

DC Coleman February 14, 2001


What I get is...

Connect string: WinNT://domain/myname,user

error '800401e4'
Invalid syntax
/names/ChangePassword1.asp, line 15

...where line 15 is:

Set oUser = GetObject(sConnectString)

Can't find the reference in MSDN. Any idea?

tia,
doc

Doc February 22, 2001


<i>I downloaded the code from the web and tested it.

First, when you download it, change the file extensions from .txt to .asp. You also need to change the name of Listing 2 - ChangePassword1.asp to ChangePassword1.asp.

You may also need to change the Action parameter of the form in the first file (Listing 1) to point to the correct path for ChangePassword1.asp.

After making these changes, I tested the code and it works correctly. I used it to change passwords on Win2k Pro and Win2k Server both as standalone systems.

Good luck,

Ken</i>

Ken February 27, 2001


I keep getting Event Id 627, Change Password Attempt failures on my domain controller, by the Anonymous account, when trying to change passwords using these scripts. I als have tried the IISADMPWD scripts that came with iis. CHanging the accounts local to the web server, work fine. The virtual website has been tried as NTLM and Basic Authentication. I've set ACL's on the .asp files to NO Access for anonymous. Any ideas?

Jim Wilson April 04, 2001


If the specified user id was not found then it gives an ASP error.how to query SAM to find whether a user exists or not

chndrabhanu April 21, 2001


Has anyone been able to get this to work on a Win2k server with Active Directory enabled? My problem is with the sConnectString statment, or better yet the ldap statment that follows it.
<br><br>
Any help will be much appreciated
Thanks,


Michael Brown June 12, 2001


I havent been able to get this code work on W2K too, I tried almost anything but the only thing I`ve been able to get is "Internal server error"...

Aleksandar Z. June 26, 2001


 See More Comments  1   2 

You must log on before posting a comment.

If you don't have a username & password, please register now.




Top Viewed ArticlesView all articles
PsExec

This freeware utility lets you execute processes on a remote system and redirect output to the local system. ...

Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

How can I stop and start services from the command line?

...


Windows OSs Whitepapers Why SaaS is the Right Solution for Log Management

Related Events How IE7 & The New Extended Validation SSL Certificates Impact Your Site

Concrete Ways to Make Sure Your SharePoint Deployment Doesn't Blow Up

Check out our list of Free Email Newsletters!

Windows OSs eBooks Understanding and Leveraging Code Signing Technologies

A Guide to Windows Certification and Public Keys

SQL Server Administration for Oracle DBAs

Related Windows OSs Resources Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro Windows Dev Pro IT Job Hound ITTV
IT Library Technology Resource Directory Connected Home Windows Excavator Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2008 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing