Click here to Skip to main content
15,886,799 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: Asp .net application performance issues using JavaScript to open the application’s asp pages. Pin
Richard Deeming21-Jun-16 9:01
mveRichard Deeming21-Jun-16 9:01 
GeneralRe: Asp .net application performance issues using JavaScript to open the application’s asp pages. Pin
Stephen Holdorf21-Jun-16 9:18
Stephen Holdorf21-Jun-16 9:18 
GeneralRe: Asp .net application performance issues using JavaScript to open the application’s asp pages. Pin
Richard Deeming21-Jun-16 9:36
mveRichard Deeming21-Jun-16 9:36 
QuestionProblem adding source to sitemap. Pin
larsp77721-Jun-16 3:11
larsp77721-Jun-16 3:11 
QuestionHow to Change Password in ASP.NET connect to Ldap authentication Pin
Yosua Michael20-Jun-16 14:09
Yosua Michael20-Jun-16 14:09 
AnswerRe: How to Change Password in ASP.NET connect to Ldap authentication Pin
Richard Deeming21-Jun-16 2:04
mveRichard Deeming21-Jun-16 2:04 
GeneralRe: How to Change Password in ASP.NET connect to Ldap authentication Pin
Yosua Michael21-Jun-16 14:33
Yosua Michael21-Jun-16 14:33 
GeneralRe: How to Change Password in ASP.NET connect to Ldap authentication Pin
Richard Deeming22-Jun-16 3:20
mveRichard Deeming22-Jun-16 3:20 
So you're saying that you haven't written the ChangePassword method on the LdapAuthentication class, and you're surprised that you get a compiler error when you try to call a method that doesn't exist? D'Oh! | :doh:

This StackOverflow thread[^] has several examples. You'll want the ones that use the "change password" method, not the "set password" ones.

For example:
C#
public bool ChangePassword(string domainName, string userName, string currentPassword, string newPassword)
{
    string domainAndUsername = domainName + @"\" + userName;
    DirectoryEntry entry = new DirectoryEntry(_path, domainAndUsername, currentPassword);
    if (entry == null) return false;
    
    DirectorySearcher search = new DirectorySearcher(directionEntry);
    search.Filter = "(SAMAccountName=" + userName + ")";
    SearchResult result = search.FindOne();
    if (result == null) return false;
    
    DirectoryEntry userEntry = result.GetDirectoryEntry();
    if (userEntry == null) return false;
    
    userEntry.Invoke("ChangePassword", new object[] { currentPassword, newPassword });
    userEntry.CommitChanges();
    return true;
}


It might be easier to use the DirectoryServices.AccountManagement classes instead of the raw DirectoryServices classes:
C#
public class LdapAuthentication
{
    private readonly ContextType _contextType;
    
    public LdapAuthentication(ContextType contextType)
    {
        _contextType = contextType;
    }
    
    public bool IsAuthenticated(string username, string password)
    {
        using (var context = new PrincipalContext(_contextType))
        {
            return context.ValidateCredentials(username, password);
        }
    }
    
    public string GetGroups(string username)
    {
        using (var context = new PrincipalContext(_contextType))
        using (var user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, username))
        {
            if (user == null)
            {
                throw new InvalidOperationException(string.Format("User account '{0}' was not found.", username));
            }
            
            var groups = user.GetAuthorizationGroups();
            return string.Join("|", groups.Select(g => g.Name));
        }
    }
    
    public bool ChangePassword(string username, string currentPassword, string newPassword)
    {
        using (var context = new PrincipalContext(_contextType))
        using (var user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, username))
        {
            if (user == null)
            {
                throw new InvalidOperationException(string.Format("User account '{0}' was not found.", username));
            }
            
            try
            {
                user.ChangePassword(currentPassword, newPassword);
                return true;
            }
            catch (PasswordException)
            {
                return false;
            }
        }
    }
}




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: How to Change Password in ASP.NET connect to Ldap authentication Pin
Yosua Michael22-Jun-16 21:34
Yosua Michael22-Jun-16 21:34 
GeneralRe: How to Change Password in ASP.NET connect to Ldap authentication Pin
Richard Deeming23-Jun-16 1:56
mveRichard Deeming23-Jun-16 1:56 
GeneralRe: How to Change Password in ASP.NET connect to Ldap authentication Pin
Yosua Michael23-Jun-16 16:23
Yosua Michael23-Jun-16 16:23 
GeneralRe: How to Change Password in ASP.NET connect to Ldap authentication Pin
Richard Deeming27-Jun-16 3:05
mveRichard Deeming27-Jun-16 3:05 
QuestionHow to implement MULTIPLE.OPERATIONS functionality in .net Pin
Raghavendra.Kodimala18-Jun-16 22:03
professionalRaghavendra.Kodimala18-Jun-16 22:03 
QuestionRe: How to implement MULTIPLE.OPERATIONS functionality in .net Pin
ZurdoDev20-Jun-16 2:18
professionalZurdoDev20-Jun-16 2:18 
AnswerRe: How to implement MULTIPLE.OPERATIONS functionality in .net Pin
Raghavendra.Kodimala20-Jun-16 3:43
professionalRaghavendra.Kodimala20-Jun-16 3:43 
GeneralRe: How to implement MULTIPLE.OPERATIONS functionality in .net Pin
ZurdoDev20-Jun-16 3:48
professionalZurdoDev20-Jun-16 3:48 
AnswerRe: How to implement MULTIPLE.OPERATIONS functionality in .net Pin
Richard MacCutchan20-Jun-16 4:03
mveRichard MacCutchan20-Jun-16 4:03 
GeneralRe: How to implement MULTIPLE.OPERATIONS functionality in .net Pin
Raghavendra.Kodimala20-Jun-16 23:59
professionalRaghavendra.Kodimala20-Jun-16 23:59 
GeneralRe: How to implement MULTIPLE.OPERATIONS functionality in .net Pin
Richard MacCutchan21-Jun-16 0:20
mveRichard MacCutchan21-Jun-16 0:20 
GeneralRe: How to implement MULTIPLE.OPERATIONS functionality in .net Pin
Raghavendra.Kodimala21-Jun-16 22:01
professionalRaghavendra.Kodimala21-Jun-16 22:01 
GeneralRe: How to implement MULTIPLE.OPERATIONS functionality in .net Pin
Richard MacCutchan21-Jun-16 22:51
mveRichard MacCutchan21-Jun-16 22:51 
GeneralRe: How to implement MULTIPLE.OPERATIONS functionality in .net Pin
Raghavendra.Kodimala22-Jun-16 1:54
professionalRaghavendra.Kodimala22-Jun-16 1:54 
QuestionIE version problem Pin
parthi_src17-Jun-16 21:44
parthi_src17-Jun-16 21:44 
AnswerRe: IE version problem Pin
Nathan Minier20-Jun-16 1:27
professionalNathan Minier20-Jun-16 1:27 
GeneralRe: IE version problem Pin
parthi_src21-Jun-16 7:05
parthi_src21-Jun-16 7:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.