views:

68

answers:

1

I am using active directory in my ASP.NET project and whenever user register in the site,an account is created in AD. There is an Forgot Password link.Is it possible to get user password from AD.I can get the name or email, but I don't know if I can get the password.

Regards, Abhimanyu

+3  A: 

That is impossible. I would suggest that you do not implement 'forgot password' functionality, but rather 'reset password'. You generate a new password, reset the password in Active Directory and send the new password to the user.

EDIT: Based on the information in your comment. First of all, it is a very bad idea to use an administrator account the way you use it now, with the account name and password as part of your code. You're running an ASP.NET site, so you should configure the application pool to run with this account.

Second, you should simply create a DirectoryEntry with the correct path and reset the password. I'm not sure what your oEntry is:

var userEntry = new DirectoryEntry(
    "LDAP://CN=SomeUser,OU=Users,DC=yourdomain,DC=com");
using (userEntry)
{
    userEntry.Invoke("SetPassword", new object[] { "NewPassword" });
    userEntry.CommitChanges();
}
Ronald Wildenberg
@Ronald, if i want to reset password programatically,then we have to user old password for accessing the user from AD? Then how we can reset the password. Is there any other method than i choosen
Abhimanyu
@Abhimanyu - You don't need the old user password to reset a password. You just need sufficient rights (Account Operator).
Ronald Wildenberg
@Ronald - I am using the following code to reset, DirectoryEntry oEntry = new DirectoryEntry("path", "admin", "pwd"); DirectoryEntry uEntry = new DirectoryEntry(Label2.Text); uEntry.Invoke("SetPassword", new object[] { newPwd }); uEntry.Properties["LockOutTime"].Value = 0; //unlock account uEntry.Close(); but it's not working.I am giving the sufficient rights
Abhimanyu
I'm going to add some additional information to my answer in a minute...
Ronald Wildenberg
@Roanlod - ok..
Abhimanyu