Change a Users Password in Active Directory

All,

Do you know of how to change a Users password within active directory, with C#?
Thank you all in advance.
-tdaley
0
tdaley
4/29/2004 3:24:04 PM
asp.net.active-directory-ldap 2291 articles. 0 followers. Follow

3 Replies
734 Views

Similar Articles

[PageSpeed] 2

Well after some looking around I have solved this issue.

The following code is to enable a user to change his/her password:
This is basing the current account credentials as:
username: User
password: OldPass

string UserAccountName = "User";
string OldPassword = "OldPass";
string NewPassword = "NewPass";
string sPath = "LDAP://dc=my, dc=domain, dc=com"; //This is if your domain was my.domain.com
DirectoryEntry de = new DirectoryEntry(sPath, "" + UserAccountName + "", "" + OldPassword + "", AuthenticationTypes.Secure);
DirectorySearcher ds = new DirectorySearcher(de);
string qry = string.Format("(&(objectCategory=person)(sAMAccountName={0}))", UserAccountName);
ds.Filter = qry;
ds.Sort.PropertyName = "CN";
try
{
SearchResult sr = ds.FindOne();
DirectoryEntry user = sr.GetDirectoryEntry();
user.Invoke("ChangePassword", new object[]{"" + OldPassword + "", "" + NewPassword + ""});
user.CommitChanges();
}
finally
{
}

Then this code allows the account to be changed via an Admin:
This is basing the current Admin account credentials as:
username: Admin
password: AdminPass

string AdminAccountName = "Admin";
string AdminPassword = "AdminPass";
string Username = "User"
string NewPassword = "NewPass";
string sPath = "LDAP://dc=my, dc=domain, dc=com"; //This is if your domain was my.domain.com
DirectoryEntry de = new DirectoryEntry(sPath, "" + AdminAccountName + "", "" + AdminPassword + "", AuthenticationTypes.Secure);
DirectorySearcher ds = new DirectorySearcher(de);
string qry = string.Format("(&(objectCategory=person)(sAMAccountName={0}))", Username);
ds.Filter = qry;
ds.Sort.PropertyName = "CN";
try
{
SearchResult sr = ds.FindOne();
DirectoryEntry user = sr.GetDirectoryEntry();
user.Invoke("SetPassword", new object[]{"" + NewPassword + ""});
user.CommitChanges();
}
finally
{
}

Hope that this helps anyone.
-tdaley
0
tdaley
4/29/2004 8:58:31 PM
You can also refer to the Mother-Of-All-Discussions-On-SetPassword.

Page 1 is the meat of it. There are many issues to consider when choosing to reset passwords over the web.
Ryan Dunn
Weblog
The Book
LDAP Programming Help
0
dunnry
5/7/2004 4:07:43 PM
Dunnry,

Thanks, that was the post that I used to get the info for my final code. I might as well just look at any post that you post in for my Active Directory needs. :) Thanks for all the help over time on these things.
-tdaley
0
tdaley
5/7/2004 4:39:23 PM
Reply:

Similar Artilces:

Net::LDAP -> Active Directory password change attribute failure
Okay, even using the code chunk from "the FAQ"(tm), trying to have a user change their own password results in the error message: 0000052D: AtrErr: DSID-03190F00, #1: 0: 0000052D: DSID-03190F00, problem 1005 (CONSTRAINT_ATT_TYPE), data 0, Att 9005a (unicodePwd) from the $ldap->modify( changes=>{delect,add} ) operation. Have tried numerous methods of encoding the password unicode (which all end up the same result) as well as base64 encoding. Strangely, if I use a "replace" operation instead of changes=>{delect,add}, it is accepted (tho i g...

RE: Net::LDAP -> Active Directory password change attribute failure
------_=_NextPart_001_01C621ED.C1F635D4 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable We use a modify/replace on the dn to change the password. However, this = operation will only succed over LDAPS and not over LDAP. Here's a sub = that we use in our account maint 'system' to change AD passwords: =20 sub _setADPasswordForUser { my ($dn, $pass) =3D @_; my $name =3D "_setADPasswordForUser"; my ( $package, $filename, $line ) =3D caller;=20 debug("$name: entering with args @_"); ...

Is there a way to authenticate Active Directory users from multiple Active Directory Domains
Is there a way to authenticate Active Directory users from multiple Active Directory Domains in ASP.NET Application using C# or VB.NET?Suppose I have a LoginId "user1" from one of the three Active Directory Domains how can I authenticate it?I have two Active Directory domains. I can authenticate from the Active Directory Domain where my current system Account is logged in. But I can not authenticate from other Active Directory Domains. Actually I have 2 Active Directory domains in my LAN.Kamran ShahidSr. Software Engineer(MCP,MCAD.net,MCSD.net,MCTS,MCPD.net[web])Netprosys Inc.ww...

How to check the username with active directory and fetch the user details from the active directory?
I have a textbox with a submit button.When the admin types the username in the textbox and submits it has to check with active directory and fetch the firstname and last name of the user entered inthe textbox.How will i do this one.Code is appreciated. you will find lot of samples if you search for "ActiveDirectory using .NET" but here is a verysimple code and it works too:-) strLANID = "ADDomainName\user"           Dim dservices As New System.DirectoryServices.DirectoryEntry        ...

Change user password in active directory.
Hi All, To change the password in active directory I have used the following code but i`m getting exception saying as Unknown error (0x80005000). Please some body help me in solving out this problem. I tried to run the "LADP://192.168.1.15” in run cmd but its giving an error msg saying as --------------------------- Find People --------------------------- An error occurred while performing the search. Your computer, your Internet service provider, or the specified directory service may be disconnected. Check your connections and try again. Operations Error ----------...

Change Password in LDAP or active directory
Hello all,I am still new to asp.net so please bear with me. I am trying to use the change password wizard in VWD 2005 to change an LDAP or active directory password. When I test it I keep getting this error message "Password incorrect or New Password invalid. New Password length minimum: 6. Non-alphanumeric characters required: 0." I know that I am putting in the right password and using the right credentials. If I am not doing this right How do I fix it? Here is my web.config if needed. Thank you.<?xml version="1.0"?><configuration>    <ap...

Allowing users to change their Active Directory Passwords....
I have a site which is using SQL Server as its membership and roles providers and it works great.  No problems here. Is it possible to allow users to be able to change their Active Directory password via the website while still maintaining the existing membership functionality for the website?  How would you do this? (VB.net please) All help will be greatly appreciated.  Thanks"Please remember to "Mark as Answer" if the post that helps you. Thanks" HiYou need a System.DirectoryServices assembly and invoke the "SetPassword" method to main...

Net::LDAP, Active Directory and Disabled Users
------_=_NextPart_001_01C386CB.502F3B30 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I've been trying to write a simple perl script that will query the = active directory via LDAP and give me a list of email addresses for disabled = users (eg, addresses we don't want to accept email for anymore). I found a = website or two that suggested I use the following as my filter: (&(objectCategory=3Dperson)(userAccountControl:1.2.840.113556.1.4.803:=3D= 2)) I was beginning to think these websites were wrong as whene...

RE: Net::LDAP, Active Directory and Disabled Users
Version of Perl:=20 5.8.0 (as supplied with RedHat9) Version of Net::LDAP: [jsteenha@jake utilities]$ perl -mNet::LDAP -e 'print = "$Net::LDAP::VERSION\n"' 0.29 Relevant part of Perl code: #!/usr/bin/perl use Net::LDAP; use Net::LDAP::Filter; $filter =3D = '(&(objectCategory=3Dperson)(userAccountControl:1.2.840.113556.1.4.803:=3D= 2))'; #$filter =3D '(objectCategory=3Dperson)'; $f =3D new Net::LDAP::Filter; $f->parse($filter); $f->print(); #exit; my $ldap =3D Net::LDAP->new('acutex-dc01'); my $mesg =3D $...

Net::LDAP, Active Directory and Disabled Users #2
I've been trying to write a simple perl script that will query the active directory via LDAP and give me a list of email addresses for disabled users (eg, addresses we don't want to accept email for anymore). I found a website or two that suggested I use the following as my filter: (&(objectCategory=person)(userAccountControl:1.2.840.113556.1.4.803:=2)) I was begining to think these websites were wrong as whenever I tried this filter, I'd go no results. With other filters, I'd get the results I'd expect to get. I then tried that filter in a couple other appli...

Active Directory user home directory
Hi all. I have a question, how to sync home directorires of users from Identity Vault to Active Directory? Into AD there are 2 LDAP attributes calleds homeDrive (the network drive letter) and homeDirectory that is the network path used to map during user login. My doubt is about the eDirectory volume information. The volume will be not sync to the AD because AD does not recognize this information, right? So, how to sync? I was thinking about create 2 eDirectory attributes where I can write theese informations. What do you think about this? Anyone can help me? Best regards...

Return All Users with User Groups from Active Directory with LDAP
Hello.  I am trying to write a report that pulls information in from Active Directory.  I have a view created that gets a listing of users and a view that creates a listing of user groups, but I can't seem to figure out how to get all user groups that are associated with the users.  This is what I have. SELECT     *FROM         OPENQUERY(ADSI, 'SELECT objectSid, samAccountName, distinguishedName FROM ''LDAP://wmdomain.local''WHERE objectClass = ''User''')    ...

Active Directory
Could somebody please point me in the right direction?  I'm attempting to make a website pulling information from active directory.  I am able to pull specific user information using VBS but am very lost as to how to port this type of stuff over to a website.  Could somebody please post some examples or websites showing how to display maybe just all users from AD? Thanks so much. ...

Changing an Active Directory password
I am looking for an example that demonstates how to change/update an active directory user's password and enable "Change password on next login".  I am able to pull AD users information from LDAP, but am unfamiliar with what fields and syntax to update a specified user.  Any examples or link would be benficial.  VB is preferred.  Thanks Hi scott1101, From your description, I guess you're using Forms Authentication, right? If so, I suggest you to use ActiveDirectoryMembershipProvider instead. With this provider, you'll have no need to st...

Web resources about - Change a Users Password in Active Directory - asp.net.active-directory-ldap

Wikipedia:Quick directory - Wikipedia, the free encyclopedia
This page is a handy directory to various locations of interest in Wikipedia. Only dynamic pages should be listed here, no policy pages etc. ...

Wikipedia:WikiProject Council/Directory - Wikipedia, the free encyclopedia
Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc. , a non-profit organization.

Business Directory Listings: Eight Smart Tips for You to Get Started
If you are considering a business directory listing for your small business, congratulations – you are on the right track. Local SEO, local customers, ...

LinkedIn Lookup iOS app aims to replace your company’s awful intranet employee directory
... continue reading at 9to5Mac . What do you think? Discuss "LinkedIn Lookup iOS app aims to replace your company’s awful intranet employee directory" ...

Atlas Partner Directory Launched
... just for Facebook and Instagram –advertising platform Atlas has one, as well. On that note, Atlas Tuesday introduced the Atlas Partner Directory ...

Slack announces App Directory store
... create more apps for the store, and a new framework called Botkit which should simplify the process of creating apps. The Slack App Directory, ...

The British Library’s ‘Save Our Sounds’ Program Creates Directory of UK Sound Collections
The long-feared deterioration of the world's sound collections is a coming to a head with the British Library's last-ditch initiative called ...

Researchers show how to steal Windows Active Directory credentials from the Internet
... showed at the Black Hat security conference. The attack, called an SMB relay, causes a Windows computer that's part of an Active Directory ...

Researchers find way to steal Windows Active Directory credentials from the Internet
The technique could enable attackers to attack Windows servers hosted in the cloud

Slack's App Directory proves it's more than just a chatroom
... are about to get a little easier to find and integrate within your team and over 160 of them live within the company's new Slack App Directory. ...

Resources last updated: 12/27/2015 4:52:55 AM