
General Security Practices for Login Controls
Securing login controls involves following best practices in a number of areas which are covered briefly below with links leading to more information.
Using Secure Sockets Layer (SSL) Protocol
ASP.NET login controls transmit information to the server in plain text over HTTP. When you are dealing with sensitive information, it is strongly recommended that you use HTTPS protocol with secure sockets layer (SSL) encryption. SSL protects against data being altered (data integrity), protects a user's identity (confidentiality), and assures that data originates from the expected client (authentication). For more information, see Cryptography Overview and Configuring SSL on a Web Server or a Web Site in the IIS documentation.
Validating User Input
Never assume that input you get from users is safe. Malicious users can send potentially dangerous information from the client to your application. For login controls, it is especially important to take precautions with user input because the information being entered is often sensitive. For more information about guarding against malicious input, see Basic Security Practices for Web Applications.
Whenever practical, use validation controls to test for valid user names and for strong passwords. You can validate some user input without validation controls. For example, the CreateUserWizard control supports required and comparison validation. You can also specify a regular expression with the EmailRegularExpression property to validate that e-mail addresses match a specified pattern and with the PasswordRegularExpression property to validate that passwords meet your requirements.
For the most flexibility in validating user input in login controls, you can use templates. Whenever possible, create a template for the control, add individual controls (typically TextBox controls), and add validation controls to restrict the user's input to the narrowest allowable input.
Note: |
|---|
When using validation controls, always perform validation in server code in addition to using client-side validation. This helps prevent users from bypassing validation by disabling or changing the client script check.
|
For more information, see Validating User Input in ASP.NET Web Pages.
Securing View State
Login controls store information in the page's view state, so it is a best security practice to secure view state. Although view state data is stored in an encoded format, it can be viewed and tampered with. For more information, see ASP.NET View State Overview.
Securing Membership
ASP.NET membership provides functionality for validating and storing user credentials. The CreateUserWizard, Login, PasswordRecovery, and ChangePassword controls use ASP.NET membership to enable you to create a complete authentication system that requires little or no code. Additionally, the LoginName, LoginStatus, and LoginView controls can be used to complete your solution for handling user membership and controlling access to pages within your Web site. For more information, see Introduction to Membership and Securing Membership.
Membership providers shipped with ASP.NET have a built-in threshold for the maximum number of invalid password or password answer attempts, as specified in the MaxInvalidPasswordAttempts property. ASP.NET membership also enables you to configure the number of minutes in which a maximum number of invalid password or password answer attempts are allowed before the membership user is locked out, as specified in the PasswordAttemptWindow property. The default password attempt threshold is 5, and the default password attempt window is 10 minutes. Thresholds in the default providers can be overridden by thresholds set in the membership section of the application's Web.config file. It is recommended that if you set these thresholds, you set the values as low as practical. Additionally, it is recommended that you do not set the RequiresQuestionAndAnswer property to false, because invalid password answer attempts will not be tracked. For more information, see Membership Providers.
Securing E-Mail
The CreateUserWizard, ChangePassword, and PasswordRecovery controls can send e-mail messages with details about the completed user transaction. Ensure that any e-mail messages sent to users reveal only necessary information. For example, avoid making the subject line of the e-mail messages easy for unintended parties to filter from other e-mail messages. It is recommended that you avoid sending passwords in e-mail. Consider other methods of verifying password transactions, such as sending a confirmation code and a return URL that requires users to use the URL to complete the transaction.
If the MailDefinition property of the CreateUserWizard, ChangePassword, and PasswordRecovery controls is not specified, then no e-mail message is sent. When these controls are configured to send e-mail messages, it is recommended that you handle the mail error event to catch any SMTP-related errors to avoid revealing unnecessary information to users. For the ChangePassword control, handle the SendMailError and set the Handled property of the SendMailErrorEventArgs object to true. For an example that shows how to handle a mail error event, see SendMailError event. For more information on installing the Simple Mail Transfer Protocol (SMTP) service, see How to: Install and Configure SMTP Virtual Servers in IIS 6.0.