Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jan 28, 2013 01:21 AM by Angie xu - MSFT
0 Points
6 Posts
Jan 21, 2013 07:54 AM|LINK
When i try to reset password i got an error that is :
Exception has been thrown by the target of an invocation.
System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
public static Boolean ResetPassword(string DomainId, string setpassword) { PrincipalContext pr = new PrincipalContext(ContextType.Domain, "domain.org", "dc=domain,dc=org", "administrator", "P@ssw0rd"); UserPrincipal user = UserPrincipal.FindByIdentity(pr, DomainId); Boolean flag = false; if (user != null && user.Enabled == true) { user.SetPassword(setpassword); user.Save(); flag = true; } else { flag = false; } user.Dispose(); pr.Dispose(); return flag; }
Member
66 Points
30 Posts
Jan 21, 2013 08:02 AM|LINK
Check
http://forums.asp.net/t/1709380.aspx/1?Resetting+a+user+s+password+across+domains
http://forums.asp.net/t/1659012.aspx/1
http://forums.asp.net/t/1619255.aspx/1
Jan 21, 2013 08:54 AM|LINK
Nothing work with me
All-Star
20277 Points
1726 Posts
Microsoft
Jan 28, 2013 01:21 AM|LINK
Hi Ahmed
You could refer these codes to reset password,
public static Boolean ResetPassword(string username, string password, string DomainId, string setpassword, Boolean UnlockAccount,Boolean NextLogon)
{ PrincipalContext pr = new PrincipalContext(ContextType.Domain, "corp.local", "dc=corp,dc=local", username, password);
UserPrincipal user = UserPrincipal.FindByIdentity(pr, DomainId);
Boolean flag = false;
if (user != null && user.Enabled == true)
{ if (UnlockAccount)
{user.UnlockAccount(); }
user.SetPassword(setpassword);
if (NextLogon)
{user.ExpirePasswordNow();}
user.Save();
flag = true;
}
else
{ flag = false; }
user.Dispose();
pr.Dispose();
return flag;
You could also get some tips from the discussion in stackoverflow.
hope it helps you,
KInd regards
Ahmed.Gebaly
0 Points
6 Posts
Reset password
Jan 21, 2013 07:54 AM|LINK
When i try to reset password i got an error that is :
Exception has been thrown by the target of an invocation.
System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
public static Boolean ResetPassword(string DomainId, string setpassword) { PrincipalContext pr = new PrincipalContext(ContextType.Domain, "domain.org", "dc=domain,dc=org", "administrator", "P@ssw0rd"); UserPrincipal user = UserPrincipal.FindByIdentity(pr, DomainId); Boolean flag = false; if (user != null && user.Enabled == true) { user.SetPassword(setpassword); user.Save(); flag = true; } else { flag = false; } user.Dispose(); pr.Dispose(); return flag; }dotnetlover ...
Member
66 Points
30 Posts
Re: Reset password
Jan 21, 2013 08:02 AM|LINK
Check
http://forums.asp.net/t/1709380.aspx/1?Resetting+a+user+s+password+across+domains
http://forums.asp.net/t/1659012.aspx/1
http://forums.asp.net/t/1619255.aspx/1
Ahmed.Gebaly
0 Points
6 Posts
Re: Reset password
Jan 21, 2013 08:54 AM|LINK
Nothing work with me
Angie xu - M...
All-Star
20277 Points
1726 Posts
Microsoft
Re: Reset password
Jan 28, 2013 01:21 AM|LINK
Hi Ahmed
You could refer these codes to reset password,
public static Boolean ResetPassword(string username, string password, string DomainId, string setpassword, Boolean UnlockAccount,Boolean NextLogon)
{ PrincipalContext pr = new PrincipalContext(ContextType.Domain, "corp.local", "dc=corp,dc=local", username, password);
UserPrincipal user = UserPrincipal.FindByIdentity(pr, DomainId);
Boolean flag = false;
if (user != null && user.Enabled == true)
{ if (UnlockAccount)
{user.UnlockAccount(); }
user.SetPassword(setpassword);
if (NextLogon)
{user.ExpirePasswordNow();}
user.Save();
flag = true;
}
else
{ flag = false; }
user.Dispose();
pr.Dispose();
return flag;
}
You could also get some tips from the discussion in stackoverflow.
hope it helps you,
KInd regards
Feedback to us
Develop and promote your apps in Windows Store