Home > ASP.Net > Create Login Page Programaticaly

Create Login Page Programaticaly


Hi

try this example:

http://www.asp.net/LEARN/security/tutorial-06-cs.aspx

create Login.aspx page and add two textboxes (UserName.Password) and two lables and button control
and checkbox (RememberMe) and two RequiredFieldValidator and one RegularExpressionValidator control
Login.aspx

<asp:TextBox ID="UserName" runat="server" ></asp:TextBox>
  <asp:RequiredFieldValidator ID="UserNameRequired" runat="server"
     ControlToValidate="UserName"
     ErrorMessage="UserName is Required."
     ToolTip="UserName is Required."
     ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>

<asp:TextBox ID="Password" runat="server"
     TextMode="Password"></asp:TextBox>
  <asp:RequiredFieldValidator ID="PasswordRequired" runat="server"
     ControlToValidate="Password"
     ErrorMessage="Password is required."
     ToolTip="Password is required."
     ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
  <asp:RegularExpressionValidator ID="RegularExpressionValidator1"
     runat="server"
     ControlToValidate="Password"
     ErrorMessage="Must have at least 1 number, 1 special character,
        and more than 6 characters."
     ValidationExpression= "(?=^.{6,}$)(?=.*\d)(?=.*\W+)(?![.\n]).*$">*</asp:RegularExpressionValidator>

<asp:CheckBox ID="RememberMe" runat="server" Text="Remember Me" />

<asp:Button ID="LoginButton" runat="server" Text="Login" ValidationGroup="CreateUserWizard1" OnClick="LoginButton_Click" />

Login.asox.cs

protected void LoginButton_Click(object sender, EventArgs e)
{
     // Validate the user against the Membership framework user store
     if (Membership.ValidateUser(UserName.Text, Password.Text))
     {
          // Log the user into the site
          FormsAuthentication.RedirectFromLoginPage(UserName.Text, RememberMe.Checked);
     }
     // If we reach here, the user's credentials were invalid
     InvalidCredentialsMessage.Visible = true;
}

Good Luck

Advertisements
Categories: ASP.Net
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: