Authentication Controls
As impressive as the Membership and Roles classes are, ASP.NET v2.0 also ships with a number of authentication controls that make life easier by helping you manipulate user data and page elements based on the providers.The first and arguably most useful of the authentication controls is the Login control. This is a composite control that takes user name and password input to authenticate and log in a user. Under the covers, it calls Membership.ValidateUser(), and if the user input matches the values in the data store (as determined by the MembershipProvider), FormsAuthentication.SetAuthCookie() is called, and the user is logged in.This composite control is rendered by placing just one control in your page with <asp:Login ID="Login1" Runat="server" />. A vast array of properties enables you to customize everything from the text to the colors and validation. Everything else is taken care of for you. Figure 11.3 shows the rendered control in the browser.
Figure 11.3. The Login control as rendered in the browser.

Listing 11.10. Using the LoginView control
The PasswordRecovery control is probably the most complex of the bunch but also the most powerful. This control provides user interface elements that enable the user to change or receive his or her password by email, depending on the settings of the provider. In the first step, it asks for the user's name. In the second step, it asks for the answer to the user's question, if it's enabled. The third part is a confirmation that the password was sent or reset, again depending on the values set for the MembershipProvider.
<asp:LoginView ID="LoginView1" Runat="server">
<AnonymousTemplate>
Unknown user
</AnonymousTemplate>
<LoggedInTemplate>
Logged in user
</LoggedInTemplate>
<RoleGroups>
<asp:RoleGroup Roles="Admin">
<ContentTemplate>A user in the Admin role</ContentTemplate>
</asp:RoleGroup>
<asp:RoleGroup Roles="Moderator">
<ContentTemplate>A user in the Moderator role</ContentTemplate>
</asp:RoleGroup>
</RoleGroups>
</asp:LoginView>