<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Security</title><link>http://forums.asp.net/25.aspx</link><description>All about ASP.NET security (authentication, authorization, membership, roles, etc.) and the Login controls. &lt;a href="http://aspadvice.com/SignUp/list.aspx?l=24&amp;c=17" target="_blank"&gt;Email List&lt;/a&gt;</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Re: Reset Password in Active Directory</title><link>http://forums.asp.net/thread/2349021.aspx</link><pubDate>Fri, 09 May 2008 20:02:42 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2349021</guid><dc:creator>aaguirre</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2349021.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=2349021</wfw:commentRss><description>&lt;p&gt;may be you&amp;nbsp;are using a library that does not belong to the framework and needs to be published in the COM. &lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: Reset Password in Active Directory</title><link>http://forums.asp.net/thread/2124794.aspx</link><pubDate>Tue, 22 Jan 2008 14:50:05 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2124794</guid><dc:creator>rkws</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2124794.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=2124794</wfw:commentRss><description>&lt;p&gt;This code looks so helpful but-&lt;/p&gt;
&lt;p&gt;I&amp;#39;m trying to implement it in my project and it&amp;#39;s failing when I call SetPassword.&lt;/p&gt;
&lt;p&gt;The error I get is &amp;quot;System.Runtime.InteropServices.COMException: The directory property cannot be found in the cache&amp;quot;&lt;/p&gt;
&lt;p&gt;Do you have any suggestions why this might be happening, what I can do?&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;</description></item><item><title>Re: Reset Password in Active Directory</title><link>http://forums.asp.net/thread/2080429.aspx</link><pubDate>Fri, 28 Dec 2007 09:58:46 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2080429</guid><dc:creator>Jaff</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2080429.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=2080429</wfw:commentRss><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve implemented&amp;nbsp;the same solution but I&amp;#39;m still getting error. Below are my coding. Anything I&amp;#39;ve done wrongly? App + Web and the AD server&amp;nbsp;is on Win 2k platform.&lt;/p&gt;
&lt;p&gt;DirectoryEntry de = oDE = new DirectoryEntry(LDAPConnectionString, adminID, AdminPassword, AuthenticationTypes.Secure);&lt;/p&gt;
&lt;p&gt;DirectorySearcher deSearch = new DirectorySearcher();&lt;br /&gt;deSearch.SearchRoot = de;&lt;/p&gt;
&lt;p&gt;deSearch.Filter = &amp;quot;(&amp;amp;(objectClass=user)(objectCategory=person)(samaccountname=&amp;quot; + UserID + &amp;quot;))&amp;quot;;&lt;br /&gt;deSearch.SearchScope = SearchScope.Subtree;&lt;br /&gt;SearchResult searchResult = deSearch.FindOne();&lt;/p&gt;
&lt;p&gt;IntPtr token = IntPtr.Zero;&lt;br /&gt;bool result = LogonUser(adminID, Domain, AdminPassword, 3, 0, ref token);&lt;/p&gt;
&lt;p&gt;if (!result)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;int errCode = GetLastError();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; string errMessage = String.Empty;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; switch (errCode)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case 5:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; errMessage = &amp;quot;Access Denied&amp;quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case 1326:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; errMessage = &amp;quot;Logon failure: unknown user name or bad password.&amp;quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; throw new Exception(String.Format(&amp;quot;GetLastError() returned: {0}, \&amp;quot;{1}\&amp;quot;&amp;quot;, errCode, errMessage));&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;WindowsIdentity wi = new WindowsIdentity((token));&lt;br /&gt;&amp;nbsp;WindowsImpersonationContext wic = wi.Impersonate();&lt;/p&gt;
&lt;p&gt;&amp;nbsp;// Reset user&amp;#39;s password&lt;br /&gt;&amp;nbsp;UserEntry.Invoke(&amp;quot;SetPassword&amp;quot;, new object[] { resetPwd });&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; UserEntry.CommitChanges();&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; wic.Undo();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CloseHandle(token);&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;Thanks.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: Reset Password in Active Directory</title><link>http://forums.asp.net/thread/407277.aspx</link><pubDate>Mon, 01 Dec 2003 17:41:18 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:407277</guid><dc:creator>dunnry</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/407277.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=407277</wfw:commentRss><description>There is more information about SetPassword and samples in another post : &lt;a href="/AspNetForums/ShowPost.aspx?&amp;PostID=316534"&gt;view post 316534&lt;/a&gt;
&lt;br /&gt;

&lt;br /&gt;
I would recommend reading the post - it is long, but informative.  Also, I would recommend using the sample code in this post rather than the sample posted above.</description></item><item><title>Re: Reset Password in Active Directory</title><link>http://forums.asp.net/thread/406686.aspx</link><pubDate>Sun, 30 Nov 2003 23:46:29 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:406686</guid><dc:creator>ppinter1</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/406686.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=406686</wfw:commentRss><description>&lt;br /&gt;
Whoa. This almost never happens: I think I've got the fix here!
&lt;br /&gt;

&lt;br /&gt;
On Win2003Server, using AD Users and Computers console, select View-&amp;gt;Advanced Features menu. This enables extra visibility to Security tabs that otherwise remain invisible.
&lt;br /&gt;

&lt;br /&gt;
For my college, I've created a new Organizational Unit (OU) called 'Students', under the main AD domain called mycollege.edu.
&lt;br /&gt;

&lt;br /&gt;
I need my Web application to create new AD Users under that OU. Okay so far?
&lt;br /&gt;

&lt;br /&gt;
Here's my draft C# code to add a student:
&lt;br /&gt;

&lt;br /&gt;
		private bool AddUser (string UserName, string Password)
&lt;br /&gt;
		{
&lt;br /&gt;
			if (UserExists (UserName)) return false;
&lt;br /&gt;

&lt;br /&gt;
			try
&lt;br /&gt;
			{
&lt;br /&gt;
				string path = &amp;quot;LDAP://server.mycollege.edu/OU=Students,DC=mycollege,DC=edu&amp;quot;;
&lt;br /&gt;

&lt;br /&gt;
				DirectoryEntry entry	= new DirectoryEntry (path,&amp;quot;mycollege.edu\\registrar&amp;quot;,&amp;quot;secret&amp;quot;,AuthenticationTypes.Secure);
&lt;br /&gt;

&lt;br /&gt;
				DirectoryEntry user		= entry.Children.Add (&amp;quot;CN=&amp;quot;+UserName, &amp;quot;User&amp;quot;);
&lt;br /&gt;

&lt;br /&gt;
				user.Properties[&amp;quot;samAccountName&amp;quot;].Add	(UserName);
&lt;br /&gt;
				user.Properties[&amp;quot;description&amp;quot;].Add		(&amp;quot;Student Account&amp;quot;);
&lt;br /&gt;
				user.Properties[&amp;quot;givenName&amp;quot;].Add		(&amp;quot;TBA&amp;quot;);
&lt;br /&gt;
				user.Properties[&amp;quot;sn&amp;quot;].Add				(&amp;quot;TBA&amp;quot;);
&lt;br /&gt;
				user.CommitChanges();
&lt;br /&gt;

&lt;br /&gt;
				user.Invoke (&amp;quot;SetPassword&amp;quot;, new object[] {Password});	// User has to be saved prior to this step
&lt;br /&gt;
				user.Properties[&amp;quot;userAccountControl&amp;quot;].Value = 0x200;	// Create and enable a ADS_UF_NORMAL_ACCOUNT
&lt;br /&gt;
				user.CommitChanges();
&lt;br /&gt;
			}
&lt;br /&gt;
			catch (Exception ex)
&lt;br /&gt;
			{
&lt;br /&gt;
				lblStatusExt.Text = ex.Message; // Write out exception text to Label
&lt;br /&gt;
				return false;
&lt;br /&gt;
			}
&lt;br /&gt;
			return true;
&lt;br /&gt;
 }
&lt;br /&gt;

&lt;br /&gt;
Now, in AD select the Students OU, select Properties, select the Security tab and add the registrars account with full control permissions. The final trick needed is to click Advanced Permissions and, for the registrar account, ensure the Apply To field denotes 'This object and all child objects'. No workie without this last tweak.
&lt;br /&gt;

&lt;br /&gt;
While this functions, I'm wondering what others would suggest to avoid hard-coding the registrars username/password above. Web Application settings in Web.config? How secure is Web.config really? Any other ideas?
&lt;br /&gt;

&lt;br /&gt;
Anyone?</description></item><item><title>Re: Reset Password in Active Directory</title><link>http://forums.asp.net/thread/406640.aspx</link><pubDate>Sun, 30 Nov 2003 21:01:32 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:406640</guid><dc:creator>ppinter1</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/406640.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=406640</wfw:commentRss><description>Okay, it's been nearly a year since the last post on this thread. Thanks to Ryan for saving our collective butts with his excellent posts!
&lt;br /&gt;

&lt;br /&gt;
Now, has the scene changed? Has there been a more elegant way to SetPassword without resorting to hardcoded Dllimport impersonations or COM+ hacks?
&lt;br /&gt;

&lt;br /&gt;
I mean, we shouldn't have to grease IIS/AD this hard to do such a basic function!
&lt;br /&gt;

&lt;br /&gt;
Now I see why Forms Authentication (with underlying SQL or XML datastores; not AD) enjoy such prominence among Microsofts examples of authenticated web applications.
&lt;br /&gt;

&lt;br /&gt;
Anyway, I've hit the same 'feature' as the main post... I'm providing a secure userID/password on the DirectoryEntry constructor that has been 'Delegate Control' enabled to perform most all admin functions for the OU folder in my AD where the User objects are happily created, but no joy on setting an initial password.
&lt;br /&gt;

&lt;br /&gt;
Shouldn't using that fargin ID be enuf already?
&lt;br /&gt;</description></item><item><title>Re: Reset Password in Active Directory</title><link>http://forums.asp.net/thread/132627.aspx</link><pubDate>Mon, 27 Jan 2003 16:29:34 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:132627</guid><dc:creator>dunnry</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/132627.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=132627</wfw:commentRss><description>If you are only calling SetPassword, that is correct.  However, in this situation, it is necessary - you can see from the code above that other properties are being set.
&lt;br /&gt;</description></item><item><title>Re: Reset Password in Active Directory</title><link>http://forums.asp.net/thread/132522.aspx</link><pubDate>Mon, 27 Jan 2003 14:21:30 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:132522</guid><dc:creator>MariusFilipowski</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/132522.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=132522</wfw:commentRss><description>Hi, we had a similar problem. You don't have to call CommitChanges() This only applies to Properties.
&lt;br /&gt;

&lt;br /&gt;
Hope it helps</description></item><item><title>Re: Reset Password in Active Directory</title><link>http://forums.asp.net/thread/127610.aspx</link><pubDate>Mon, 20 Jan 2003 16:40:18 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:127610</guid><dc:creator>bdesmond</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/127610.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=127610</wfw:commentRss><description>FYI you can assign Act as Part of OS rights by:
&lt;br /&gt;

&lt;br /&gt;
Opening up the Group Policy console on the server
&lt;br /&gt;
Local Computer Policy
&lt;br /&gt;
Computer Config
&lt;br /&gt;
Windows Settings
&lt;br /&gt;
Sec Settings
&lt;br /&gt;
Local Policies
&lt;br /&gt;
User Rights Assignment
&lt;br /&gt;
Add ASPNET to the Act as Part of Operating System Assignment.
&lt;br /&gt;

&lt;br /&gt;
The server has to be rebooted for the change to become effective.</description></item><item><title>Re: Reset Password in Active Directory</title><link>http://forums.asp.net/thread/127185.aspx</link><pubDate>Mon, 20 Jan 2003 02:50:14 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:127185</guid><dc:creator>dunnry</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/127185.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=127185</wfw:commentRss><description>Yes, that is correct if you are using Windows 2000.  I had alluded to this in an earlier post, but forgot to mention what that right was.  Thanks for the catch.  If you are running 2003 Server or XP, you don't need to grant this right.
&lt;br /&gt;</description></item><item><title>Re: Reset Password in Active Directory</title><link>http://forums.asp.net/thread/126985.aspx</link><pubDate>Sun, 19 Jan 2003 18:43:22 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:126985</guid><dc:creator>bdesmond</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/126985.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=126985</wfw:commentRss><description>I implemented a similiar solution with LogonUser. If you're running a 2000 server, ASPNET needs act as part of the operating system rights in order to call that api.</description></item><item><title>Re: Reset Password in Active Directory</title><link>http://forums.asp.net/thread/126017.aspx</link><pubDate>Fri, 17 Jan 2003 18:57:00 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:126017</guid><dc:creator>dunnry</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/126017.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=126017</wfw:commentRss><description>Ok, here is something that should work for you:&lt;pre&gt;
&lt;br /&gt;
[DllImport(&amp;quot;C:\\WINNT\\System32\\advapi32.dll&amp;quot;)] 
&lt;br /&gt;
public static extern bool LogonUser(String lpszUsername, String lpszDomain, String lpszPassword, 
&lt;br /&gt;
			int dwLogonType, int dwLogonProvider, out IntPtr phToken); 
&lt;br /&gt;

&lt;br /&gt;
[DllImport(&amp;quot;C:\\WINNT\\System32\\Kernel32.dll&amp;quot;)] 
&lt;br /&gt;
public static extern int GetLastError(); 
&lt;br /&gt;

&lt;br /&gt;
[DllImport(&amp;quot;kernel32.dll&amp;quot;, CharSet=System.Runtime.InteropServices.CharSet.Auto)]
&lt;br /&gt;
		public static extern bool CloseHandle(IntPtr handle);
&lt;br /&gt;

&lt;br /&gt;
const int UF_SCRIPT						= 0x0001;
&lt;br /&gt;
const int UF_ACCOUNTDISABLE				= 0x0002;
&lt;br /&gt;
const int UF_HOMEDIR_REQUIRED			= 0x0008;
&lt;br /&gt;
const int UF_LOCKOUT					= 0x0010;
&lt;br /&gt;
const int UF_PASSWD_NOTREQD				= 0x0020;
&lt;br /&gt;
const int UF_PASSWD_CANT_CHANGE			= 0x0040;
&lt;br /&gt;
const int UF_TEMP_DUPLICATE_ACCOUNT		= 0x0100;
&lt;br /&gt;
const int UF_NORMAL_ACCOUNT				= 0x0200;
&lt;br /&gt;
const int UF_INTERDOMAIN_TRUST_ACCOUNT	= 0x0800;
&lt;br /&gt;
const int UF_WORKSTATION_TRUST_ACCOUNT	= 0x1000;
&lt;br /&gt;
const int UF_SERVER_TRUST_ACCOUNT		= 0x2000;
&lt;br /&gt;
const int UF_DONT_EXPIRE_PASSWD			= 0x10000;
&lt;br /&gt;
const int UF_MNS_LOGON_ACCOUNT			= 0x20000;
&lt;br /&gt;

&lt;br /&gt;
//get ahold somehow of the user that you want to reset their password for
&lt;br /&gt;
DirectoryEntry _user = new DirectoryEntry(adPath, adminUsername, adminPassword, AuthenticationTypes.Secure);
&lt;br /&gt;

&lt;br /&gt;
/// &amp;lt;summary&amp;gt;
&lt;br /&gt;
/// Reset the user's password
&lt;br /&gt;
/// &amp;lt;/summary&amp;gt;
&lt;br /&gt;
/// &amp;lt;param name=&amp;quot;reset&amp;quot;&amp;gt;(bool) change password at next login&amp;lt;/param&amp;gt;
&lt;br /&gt;
/// &amp;lt;returns&amp;gt;user's password (string)&amp;lt;/returns&amp;gt;
&lt;br /&gt;
public string ResetPassword(bool reset)
&lt;br /&gt;
{
&lt;br /&gt;
	string sPwd = _user.Properties[&amp;quot;sAMAccountName&amp;quot;][0].ToString() + &amp;quot;.tmp&amp;quot;; //static password here
&lt;br /&gt;
	int flags;
&lt;br /&gt;
		
&lt;br /&gt;
	if(reset)
&lt;br /&gt;
	{
&lt;br /&gt;
		//first have to remove &amp;quot;Password Never Expires Flag&amp;quot;
&lt;br /&gt;
		flags = (int)_user.Properties[&amp;quot;userAccountControl&amp;quot;].Value;
&lt;br /&gt;
		if(Convert.ToBoolean(flags &amp;amp; UF_DONT_EXPIRE_PASSWD))
&lt;br /&gt;
		{
&lt;br /&gt;
			flags = (flags ^ UF_DONT_EXPIRE_PASSWD);
&lt;br /&gt;
			_user.Properties[&amp;quot;userAccountControl&amp;quot;].Value = flags;
&lt;br /&gt;
		}
&lt;br /&gt;
			
&lt;br /&gt;
		if(_user.Properties.Contains(&amp;quot;pwdLastSet&amp;quot;))
&lt;br /&gt;
			_user.Properties[&amp;quot;pwdLastSet&amp;quot;].Value = 0;
&lt;br /&gt;
		else
&lt;br /&gt;
			_user.Properties[&amp;quot;pwdLastSet&amp;quot;].Add(0);
&lt;br /&gt;
		}
&lt;br /&gt;
	else
&lt;br /&gt;
	{
&lt;br /&gt;
		//clear the change password at next login if it is there
&lt;br /&gt;
		if(_user.Properties.Contains(&amp;quot;pwdLastSet&amp;quot;))
&lt;br /&gt;
			_user.Properties[&amp;quot;pwdLastSet&amp;quot;].Value = -1;
&lt;br /&gt;
		else
&lt;br /&gt;
			_user.Properties[&amp;quot;pwdLastSet&amp;quot;].Add(-1);
&lt;br /&gt;
			
&lt;br /&gt;
		//set the password never expires flag.
&lt;br /&gt;
		flags = (int)_user.Properties[&amp;quot;userAccountControl&amp;quot;].Value;
&lt;br /&gt;
		if(!Convert.ToBoolean(flags &amp;amp; UF_DONT_EXPIRE_PASSWD))
&lt;br /&gt;
		{
&lt;br /&gt;
			flags = (flags | UF_DONT_EXPIRE_PASSWD);
&lt;br /&gt;
			_user.Properties[&amp;quot;userAccountControl&amp;quot;].Value = flags;
&lt;br /&gt;
		}
&lt;br /&gt;
	}
&lt;br /&gt;

&lt;br /&gt;
	//Change thread context to Admin's **IMPERSONATION CODE STARTS HERE**
&lt;br /&gt;
	IntPtr token = IntPtr.Zero;
&lt;br /&gt;
	string username = &amp;quot;&amp;quot;; //same as in your _user constructor
&lt;br /&gt;
	string domain = &amp;quot;&amp;quot;; //same as in your _user constructor
&lt;br /&gt;

&lt;br /&gt;
	bool result = LogonUser(username, domain , Config.Settings.AdminPassword, 3, 0, out token);
&lt;br /&gt;
	if(!result)
&lt;br /&gt;
	{
&lt;br /&gt;
		int errCode = GetLastError();
&lt;br /&gt;
		string errMessage = String.Empty;
&lt;br /&gt;
		switch(errCode)
&lt;br /&gt;
		{
&lt;br /&gt;
			case 5:
&lt;br /&gt;
				errMessage = &amp;quot;Access Denied&amp;quot;;
&lt;br /&gt;
				break;
&lt;br /&gt;
			case 1326:
&lt;br /&gt;
				errMessage = &amp;quot;Logon failure: unknown user name or bad password.&amp;quot;;
&lt;br /&gt;
				break;
&lt;br /&gt;
		}
&lt;br /&gt;
		throw new Exception(String.Format(&amp;quot;GetLastError() returned {0}, \&amp;quot;{1}\&amp;quot;&amp;quot;, errCode, errMessage));
&lt;br /&gt;
	}
&lt;br /&gt;
	else
&lt;br /&gt;
	{
&lt;br /&gt;
		WindowsIdentity wi = new WindowsIdentity(token);
&lt;br /&gt;
		WindowsImpersonationContext wic = wi.Impersonate();
&lt;br /&gt;
		_user.Invoke(&amp;quot;SetPassword&amp;quot;, new object[]{sPwd.ToLower()});				
&lt;br /&gt;
		_user.CommitChanges();
&lt;br /&gt;

&lt;br /&gt;
		wic.Undo(); //end impersonation **END IMPERSONATION**
&lt;br /&gt;
		CloseHandle(token);
&lt;br /&gt;
	}
&lt;br /&gt;
			
&lt;br /&gt;
	return sPwd.ToLower();
&lt;br /&gt;
}
&lt;br /&gt;
&lt;/pre&gt;
&lt;br /&gt;
Ok, so there is a bit of code here... just declare the DllImports and see how I am using the Impersonation code.  I have some more stuff in there because I need it to do a couple more things (like set &amp;quot;Change Password at next Login&amp;quot;).
&lt;br /&gt;

&lt;br /&gt;
Good luck, it is a little hard to cut &amp;amp; paste into this window, so I hope I did not leave anything out (it is part of much bigger class).
&lt;br /&gt;</description></item><item><title>Re: Reset Password in Active Directory</title><link>http://forums.asp.net/thread/125255.aspx</link><pubDate>Thu, 16 Jan 2003 21:26:18 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:125255</guid><dc:creator>JRing</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/125255.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=125255</wfw:commentRss><description>Well, speaking from experience, an extra component that requires registering with COM+ is a major pain so I think we'd be more interested in manipulating the ASPNET account.  If you could further explain what it is we need to do I would be much appreciative.
&lt;br /&gt;

&lt;br /&gt;
Thanks again for all your help,
&lt;br /&gt;
Josh</description></item><item><title>Re: Reset Password in Active Directory</title><link>http://forums.asp.net/thread/124946.aspx</link><pubDate>Thu, 16 Jan 2003 15:26:22 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:124946</guid><dc:creator>dunnry</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/124946.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=124946</wfw:commentRss><description>Ok, I spent an inordinate amount of time on this one as well since I last posted for a similar site that allows users to change and update passwords.  It turns out that in addition to all the things I have listed above, there is one other major (and painful) requirement:
&lt;br /&gt;

&lt;br /&gt;
SetPassword() cannot be called unless the process calling it also has Administrator credentials (i.e. the process token has Reset password right).  That means that regardless of what you are passing into the Constructor, it will fail with that &amp;quot;Error has been thrown by target of invokation&amp;quot; in ASP.NET because the aspnet_wp.exe runs always under ASPNET user account context (it would not be a good idea to change this either).
&lt;br /&gt;

&lt;br /&gt;
There are two solutions that I have found that will allow this to work:
&lt;br /&gt;

&lt;br /&gt;
1. Put the code into COM+ and set an identity of an Admin, it will run in that context and work fine.
&lt;br /&gt;
2. Impersonate an Admin for duration of SetPassword() call using Interop.  This is not the same as using &amp;lt;identity impersonate=&amp;quot;true&amp;quot; /&amp;gt; tag.  This type of impersonation I am talking about actually changes Process token to Admin.
&lt;br /&gt;

&lt;br /&gt;
The first one takes a little bit of work to get going (creating and registering .snk file), and there are a couple minor limitations on COM+ objects.  It also makes future changes to the website a little more tedious as you will have to register the COM+ object manually (no xcopy deployment here).
&lt;br /&gt;

&lt;br /&gt;
The second option lets you keep the drag and drop deployment, but on Windows 2000, requires you to give additional priviledges to the ASPNET account to make use of the underlying API that is required for impersonation.  If you are using XP or 2003 server, then it does not have this requirement.
&lt;br /&gt;

&lt;br /&gt;
Think about which way you would like to go and I can show you how to do either.
&lt;br /&gt;

&lt;br /&gt;</description></item><item><title>Re: Reset Password in Active Directory</title><link>http://forums.asp.net/thread/124928.aspx</link><pubDate>Thu, 16 Jan 2003 15:11:23 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:124928</guid><dc:creator>JRing</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/124928.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=124928</wfw:commentRss><description>SetPassword is failing</description></item></channel></rss>