Click here to Skip to main content
15,887,322 members
Home / Discussions / ASP.NET
   

ASP.NET

 
QuestionHow to display .mp4 video on Intranet Pin
David Mujica23-Jun-16 4:12
David Mujica23-Jun-16 4:12 
AnswerRe: How to display .mp4 video on Intranet Pin
2374127-Jun-16 7:33
2374127-Jun-16 7:33 
QuestionAsp .net application performance issues using JavaScript to open the application’s asp pages. Pin
Stephen Holdorf21-Jun-16 8:50
Stephen Holdorf21-Jun-16 8:50 
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 
hallo, Smile | :)
i need a help from you guys.
i have follow code from msdn how to login connect ldap.
but when i wanna change password to ldap, it won't work.

here's my LdapAuthentication.cs code:
C#
using System;
using System.Text;
using System.Collections;
using System.DirectoryServices;
using System.DirectoryServices.AccountManagement;
using System.DirectoryServices.ActiveDirectory;

namespace FormsAuth
{
    public class LdapAuthentication
    {
        private string _path;
        private string _filterAttribute;
        
        public LdapAuthentication(string path)
        {
            _path = path;
        }

        public bool IsAuthenticated(string domain, string username, string pwd)
        {
            string _domain = domain;
            string domainAndUsername = domain + @"\" + username;
            DirectoryEntry entry = new DirectoryEntry(_path, domainAndUsername, pwd);

            try
            {
                //Bind to the native AdsObject to force authentication.
                object obj = entry.NativeObject;

                DirectorySearcher search = new DirectorySearcher(entry);

                search.Filter = "(SAMAccountName=" + username + ")";
                search.PropertiesToLoad.Add("cn");
                SearchResult result = search.FindOne();

                if (null == result)
                {
                    return false;
                }

                //Update the new path to the user in the directory.
                _path = result.Path;
                _filterAttribute = (string)result.Properties["cn"][0];
            }
            catch (Exception ex)
            {
                throw new Exception("Error authenticating user. " + ex.Message);
            }

            return true;
        }

        public string GetGroups()
        {
            DirectorySearcher search = new DirectorySearcher(_path);
            search.Filter = "(cn=" + _filterAttribute + ")";
            search.PropertiesToLoad.Add("memberOf");
            StringBuilder groupNames = new StringBuilder();

            try
            {
                SearchResult result = search.FindOne();
                int propertyCount = result.Properties["memberOf"].Count;
                string dn;
                int equalsIndex, commaIndex;

                for (int propertyCounter = 0; propertyCounter < propertyCount; propertyCounter++)
                {
                    dn = (string)result.Properties["memberOf"][propertyCounter];
                    equalsIndex = dn.IndexOf("=", 1);
                    commaIndex = dn.IndexOf(",", 1);
                    if (-1 == equalsIndex)
                    {
                        return null;
                    }
                    groupNames.Append(dn.Substring((equalsIndex + 1), (commaIndex - equalsIndex) - 1));
                    groupNames.Append("|");
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error obtaining group names. " + ex.Message);
            }
            return groupNames.ToString();
        }

        
    }
}



and this is my ChangePassword.aspx code:
C#
<%@ Page Title="Change Password" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeBehind="ChangePassword.aspx.cs" Inherits="FormsAuthAd.Account.ChangePassword" %>
<%@ Import Namespace="FormsAuth" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <h2>
        Change Password
    </h2>
    <p>
        Use the form below to change your password.
    </p>
    <p>
        New passwords are required to be a minimum of <%= Membership.MinRequiredPasswordLength %> characters in length.
    </p>
    <asp:ChangePassword ID="ChangeUserPassword" runat="server" CancelDestinationPageUrl="~/Default.aspx" EnableViewState="false" RenderOuterTable="false" 
         SuccessPageUrl="ChangePasswordSuccess.aspx">
        <ChangePasswordTemplate>
            
                <asp:Literal ID="FailureText" runat="server"></asp:Literal>
            
            <asp:ValidationSummary ID="ChangeUserPasswordValidationSummary" runat="server" CssClass="failureNotification" 
                 ValidationGroup="ChangeUserPasswordValidationGroup"/>
            <div class="accountInfo">
                <fieldset class="changePassword">
                    <legend>Account Information</legend>
                    <p>
                        <asp:Label ID="Label1" runat="server">Domain:</asp:Label>
                        <asp:TextBox ID="txtDomain1" runat="server"></asp:TextBox>
                    </p>
                    <p>
                        <asp:Label ID="Label2" runat="server">Username:</asp:Label>
                        <asp:TextBox ID="txtUsername1" runat="server"></asp:TextBox>
                    </p>
                    <p>
                        <asp:Label ID="Label3" runat="server" AssociatedControlID="CurrentPassword">Old Password:</asp:Label>
                        <asp:TextBox ID="txtPassword1" runat="server" CssClass="passwordEntry" TextMode="Password"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="CurrentPasswordRequired" runat="server" ControlToValidate="CurrentPassword" 
                             CssClass="failureNotification" ErrorMessage="Password is required." ToolTip="Old Password is required." 
                             ValidationGroup="ChangeUserPasswordValidationGroup">*</asp:RequiredFieldValidator>
                    </p>
                    <p>
                        <asp:Label ID="Label4" runat="server" AssociatedControlID="NewPassword">New Password:</asp:Label>
                        <asp:TextBox ID="txtNewPassword" runat="server" CssClass="passwordEntry" TextMode="Password"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="NewPasswordRequired" runat="server" ControlToValidate="NewPassword" 
                             CssClass="failureNotification" ErrorMessage="New Password is required." ToolTip="New Password is required." 
                             ValidationGroup="ChangeUserPasswordValidationGroup">*</asp:RequiredFieldValidator>
                    </p>
                    <p>
                        <asp:Label ID="Label5" runat="server" AssociatedControlID="ConfirmNewPassword">Confirm New Password:</asp:Label>
                        <asp:TextBox ID="txtConfirmNewPassword" runat="server" CssClass="passwordEntry" TextMode="Password"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="ConfirmNewPasswordRequired" runat="server" ControlToValidate="ConfirmNewPassword" 
                             CssClass="failureNotification" Display="Dynamic" ErrorMessage="Confirm New Password is required."
                             ToolTip="Confirm New Password is required." ValidationGroup="ChangeUserPasswordValidationGroup">*</asp:RequiredFieldValidator>
                        <asp:CompareValidator ID="NewPasswordCompare" runat="server" ControlToCompare="txtNewPassword" ControlToValidate="ConfirmNewPassword" 
                             CssClass="failureNotification" Display="Dynamic" ErrorMessage="The Confirm New Password must match the New Password entry."
                             ValidationGroup="ChangeUserPasswordValidationGroup">*</asp:CompareValidator>
                    </p>
                </fieldset>
                <p class="submitButton">
                    <asp:Button ID="CancelPushButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"/>
                    <asp:Button ID="ChangePasswordPushButton" runat="server" CommandName="ChangePassword" Text="Change Password" 
                         ValidationGroup="ChangeUserPasswordValidationGroup" OnClick="Click_Change"/>
                </p>
            </div>

<script runat="server">
void Click_Change(object sender, EventArgs e)
{
   string adPath = "LDAP://my-domain.com"; //Path to your LDAP directory server
   LdapAuthentication adAuth = new LdapAuthentication(adPath);
   try
   {
      if(true == adAuth.ChangePassword(txtDomain1.Text, txtUsername1.Text, txtPassword1.Text))
      {
        Response.Redirect("~/Account/ChangePasswordSuccess.aspx");
      }
      else
      {
        errorLabel.Text = "Error Password!.";
      }
   }
   catch(Exception ex)
  {
    errorLabel.Text = "Check It. " + ex.Message;
  }
}
</script>

        </ChangePasswordTemplate>
    </asp:ChangePassword>
</asp:Content>

did i'm do something wrong?
what should i do to make void button change password will take old password and renew password to ldap?
anybody know how?
Thanks before.
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 
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 

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.