Membership.ValidateUser return: null
<p>I used AspNetSqlMembershipProvider to create a login portal</p>

<pre><code>&lt;membership defaultProvider="AspNetSqlMembershipProvider"&gt;
 &lt;providers&gt;
    &lt;remove name="AspNetSqlMembershipProvider"/&gt;
    &lt;add name="AspNetSqlMembershipProvider" requiresQuestionAndAnswer="false" enablePasswordRetrieval="false" enablePasswordReset="true" connectionStringName="MembershipDB" minRequiredPasswordLength="8" minRequiredNonalphanumericCharacters="1" applicationName="php" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/&gt;
</code></pre>

<p>However I could not login with the username and password I created, I stepped into the code and found Membership.ValidateUser return: null</p>

<p>Here is the code:</p>

<pre><code>   protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
   {
            bool UserAuthenticated = false;
            MembershipProvider AuthenticationProviderUsed = null;
            RoleProvider roleProvider = Roles.Providers["SqlRoleProvider"];
            // Try authenticating the user against each membership provider
            foreach (MembershipProvider membershipProvider in Membership.Providers)
            {
                try
                {
                    if (membershipProvider.ValidateUser(loginInitial.UserName, loginInitial.Password)) // here got null.
                    {
</code></pre>

<p>I checked the database. Both username and password are there.
Thanks for help.</p>

<h1>update: return false.</h1>

<p>Then  <code>MembershipUser user = Membership.GetUser(loginInitial.UserName);</code>user return <code>null</code>.</p>

<h1>update again: more code,</h1>

<pre><code>    protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {
            bool UserAuthenticated = false;
            MembershipProvider AuthenticationProviderUsed = null;
            RoleProvider roleProvider = Roles.Providers["SqlRoleProvider"];
            // Try authenticating the user against each membership provider
            foreach (MembershipProvider membershipProvider in Membership.Providers)
            {
                try
                {
                    if (membershipProvider.ValidateUser(loginInitial.UserName, loginInitial.Password))
                    {
                        if (base.ConfigSettings.OperatingMode == ConfigurationSettingValues.OperatingModes.NoAccess)
                        {
                            if (!roleProvider.IsUserInRole(loginInitial.UserName, ConfigurationManager.AppSettings["AdminRole"]))
                            {
                                FormsAuthentication.SignOut();
                                return;
                            }
                        }

                        MembershipUser usrInfo = Membership.GetUser(loginInitial.UserName);
                        if (membershipProvider.Name == "ActiveDirectoryMembershipProvider")
                        {
                            System.Web.Security.FormsAuthentication.SetAuthCookie(loginInitial.UserName, loginInitial.RememberMeSet);
                            UserAuthenticated = true;
                            AuthenticationProviderUsed = membershipProvider;
                            break;
                       }
                        else
                        {

                            Int16 daysSincePwdChange = Convert.ToInt16(DateTime.Now.Subtract(usrInfo.LastPasswordChangedDate).TotalDays);

                            System.Web.Security.FormsAuthentication.SetAuthCookie(loginInitial.UserName, loginInitial.RememberMeSet);

                            if (daysSincePwdChange &gt; SecurityUtils.DefaultPasswordExpiryInDays || usrInfo.Comment == "ChangePassword")
                            {
                                 e.Authenticated = false;
                                Response.Redirect("~/admin/ChangePassword.aspx?UserName=" + Server.UrlEncode(loginInitial.UserName));
                             }
                            else
                            {

                                System.Web.Security.FormsAuthentication.SetAuthCookie(loginInitial.UserName, loginInitial.RememberMeSet);
                                UserAuthenticated = true;
                                AuthenticationProviderUsed = membershipProvider;
                                break;
                            }
                        }

                   }
                    else
                    {
                        // See if the user is locked out
                        MembershipUser user = Membership.GetUser(loginInitial.UserName);
                        if (user != null &amp;&amp; user.IsLockedOut)
                        {
                            ErrorMessage.Text = "Your account is currently locked out.  Please contact the system administrator.";
                        }
                        else
                        {
                            ErrorMessage.Text = "Invalid user name and/or password";
                            //Response.Write("Invalid User Name or Password");
                        }
                    }
                }

                catch (Exception ex)
                {
                       LoggingLibrary.LogException(this.Logger, Context, ex, ex);

                }
            } 
</code></pre>

<p>The eror message is:"Invalid user name and/or password"</p>
