Shining Star Services LLC

Creating a Custom Membership Provider and Membership User utilizing a Data Set Table Adapter - Step 15

by Nannette Thacker

Our Change Password Page.

On our Change Password page, you'll notice how our change password control is wired up to use our custom membership provider:

<asp:ChangePassword ID="ChangePassword1" runat="server" SkinID="SSSCPskin1"  MembershipProvider="Shiningstar.SSSMembershipProvider"

Here is our code in front. Our code behind is very minimal because the events are all handled in the code in front.

<%@ Page Language="VB" MasterPageFile="~/SSS.master" AutoEventWireup="false"  CodeFile="PasswordChange.aspx.vb"
    Inherits="PasswordChange" Title="Change Password - ShiningStar.net and Nannette Thacker" %>

<%@ MasterType VirtualPath="~/SSS.Master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <div align="center">
        <asp:LoginView ID="LoginView1" runat="server">
            <LoggedInTemplate>
                <%--            

' getting this to work with a custom MembershipProvider
http://forums.asp.net/p/942386/1133272.aspx
http://devauthority.com/blogs/jwooley/archive/2006/08/25/2208.aspx

 --%>
                <asp:ChangePassword ID="ChangePassword1" runat="server" 
                SkinID="SSSCPskin1" MembershipProvider="Shiningstar.SSSMembershipProvider">
                    <ChangePasswordTemplate>
                        <asp:Panel runat="server" ID="ChangePasswordContainer" 
                        DefaultButton="ChangePasswordPushButton">
                            <table border="0" cellpadding="0" style="width: 400px">
                                <tr>
                                    <td align="center" colspan="2">
                                        Change Your Password
                                    </td>
                                </tr>
                                <tr>
                                    <td align="right">
                                        <asp:Label ID="CurrentPasswordLabel" runat="server" 
                                        AssociatedControlID="CurrentPassword">Password:</asp:Label>
                                    </td>
                                    <td>
                                        <asp:TextBox ID="CurrentPassword" runat="server" 
                                        Font-Size="1em" TextMode="Password"></asp:TextBox>
                                        <asp:RequiredFieldValidator ID="CurrentPasswordRequired" 
                                        runat="server" ControlToValidate="CurrentPassword"
                                            ErrorMessage="Password is required." ToolTip="Password is required." 
                                            ValidationGroup="ctl01$ChangePassword1"
                                            ForeColor="DarkRed">*</asp:RequiredFieldValidator>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="right">
                                        <asp:Label ID="NewPasswordLabel" runat="server" 
                                        AssociatedControlID="NewPassword">New Password:</asp:Label>
                                    </td>
                                    <td>
                                        <asp:TextBox ID="NewPassword" runat="server" Font-Size="1em" 
                                        TextMode="Password"></asp:TextBox>
                                        <asp:RequiredFieldValidator ID="NewPasswordRequired" runat="server" 
                                        ControlToValidate="NewPassword"
                                            ErrorMessage="New Password is required." 
                                            ToolTip="New Password is required."
                                            ValidationGroup="ctl01$ChangePassword1" 
                                            ForeColor="DarkRed">*</asp:RequiredFieldValidator>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="right">
                                        <asp:Label ID="ConfirmNewPasswordLabel" runat="server" 
                                        AssociatedControlID="ConfirmNewPassword">Confirm 
                                        New Password:</asp:Label>
                                    </td>
                                    <td>
                                        <asp:TextBox ID="ConfirmNewPassword" runat="server" 
                                        Font-Size="1em" TextMode="Password"></asp:TextBox>
                                        <asp:RequiredFieldValidator ID="ConfirmNewPasswordRequired" 
                                        runat="server" ControlToValidate="ConfirmNewPassword"
                                            ErrorMessage="Confirm New Password is required." 
                                            ToolTip="Confirm New Password is required."
                                            ValidationGroup="ctl01$ChangePassword1" 
                                            ForeColor="DarkRed">*</asp:RequiredFieldValidator>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="center" colspan="2">
                                        <div>
                                            <asp:CompareValidator ID="NewPasswordCompare" runat="server" 
                                            ControlToCompare="NewPassword"
                                                ControlToValidate="ConfirmNewPassword" Display="Dynamic" 
                                                ErrorMessage="The Confirm New Password must match the New Password entry."
                                                ValidationGroup="ctl01$ChangePassword1" 
                                                ForeColor="DarkRed"></asp:CompareValidator>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="center" colspan="2">
                                        <div>
                                            <asp:Literal ID="FailureText" runat="server" 
                                            EnableViewState="False"></asp:Literal>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="center" colspan="2">
                                        <asp:Button ID="ChangePasswordPushButton" runat="server" 
                                        ValidationGroup="ctl01$ChangePassword1"
                                            CommandName="ChangePassword" Text="Change Password" />
                                        &nbsp;&nbsp;
                                        <asp:Button ID="CancelPushButton" runat="server" 
                                        CausesValidation="False" CommandName="Cancel"
                                            Text="Reset" />
                                    </td>
                                </tr>
                            </table>
                        </asp:Panel>
                    </ChangePasswordTemplate>
                    <SuccessTemplate>
                        <table border="0" cellpadding="0" style="width: 400px">
                            <tr>
                                <td align="center">
                                    Change Password Complete
                                </td>
                            </tr>
                            <tr>
                                <td align="center">
                                    Your password has been changed!
                                </td>
                            </tr>
                        </table>
                    </SuccessTemplate>
                </asp:ChangePassword>
            </LoggedInTemplate>
            <AnonymousTemplate>
                Please
                <asp:LoginStatus ID="LoginStatus2" runat="server" />
            </AnonymousTemplate>
        </asp:LoginView>
    </div>
</asp:Content>

Code Behind

In our code behind, we simply check if the user is logged in, or isAuthenticated, and if not, redirect them to the Registration page.


Partial Class PasswordChange
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not User.Identity.IsAuthenticated = True Then
            System.Web.HttpContext.Current.Response.Redirect("~/login/Register.aspx", False)
        End If

    End Sub

End Class

We are now ready to begin Step 16.

Steps for Creating a Custom Membership Provider and Membership User utilizing a DataSet Table Adapter:

Introduction: Creating a Custom Membership Provider and Membership User utilizing a DataSet Table Adapter.
Step 1: Creating the Project and Folders.
Step 2: Table Data Structure and Web.config for this Tutorial.
Step 3: Creating The DataSet.
Step 4: Creating the Table Adapter Methods for GetUserByLogin, GetUserByUserName, and InsertUser.
Step 5: Creating our Custom MembershipProvider Class.
Step 6: Adding Properties to Our Custom MembershipProvider Class.
Step 7: Creating Our Custom MembershipUser Class.
Step 8: Customizing our MembershipProvider Class.
Step 9: Our Custom RoleProvider Class.
Step 10: Our Master page.
Step 11: Our Cookie Handler class.
Step 12: Our Log In page.
Step 13: Our Register page.
Step 14: Our Log Out page.
Step 15: Our Change Password page.
Step 16: Our Administration page.
Step 17: Loading a Menu Programmatically based on Roles.
Step 18: Our Default page.
Download the ZIP files:
VB: ShiningStarCustomMemberProviderTutorial.zip
© Copyright 1997-2017 Shining Star Services LLC, Nannette Thacker. All Rights Reserved.