Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I am creating an e-commerce website project using asp.net. I had created a login.aspx file which inside contain a login control(build inside LoginView). And user would had they account locked if they had 2 invalid password attempts within 1 min(for testing purposes). I managed to achieve this, and in the ASPNETDB, the "IsLockOut" column had changed to "True".

However, I have encountered problem with unlocking user's account. I have used the UnlockUser() method but it seem not to be working. Even if one minute had passed, user still could not logged in into the system.

This is my code behind :

protected void Login1_LoggingIn(object sender, LoginCancelEventArgs e)
{
    System.Web.UI.WebControls.Login Login1 = (System.Web.UI.WebControls.Login)LoginView1.FindControl("Login1");
    TextBox UserName = (TextBox)Login1.FindControl("UserName");

    //Check to see if the current user exists
    if (Membership.GetUser(Login1.UserName) != null)
    {
        //Check to see if the user is currently locked out
        if (Membership.GetUser(Login1.UserName).IsLockedOut)
        {
            //Get the last lockout  date from the user
            DateTime lastLockout = Membership.GetUser(Login1.UserName).LastLockoutDate;

            //Calculate the time the user should be unlocked
            DateTime unlockDate = lastLockout.AddMinutes(Membership.PasswordAttemptWindow);

            //Check to see if it is time to unlock the user
            if (DateTime.Now > unlockDate)
                Membership.GetUser(Login1.UserName).UnlockUser();
        }
    }
}


web.config:

<add name="ASPNETDBConnectionString1"
    type="System.Web.Security.SqlMembershipProvider"
    connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True"
    minRequiredPasswordLength="8"
    minRequiredNonalphanumericCharacters="0"
    requiresUniqueEmail="false"
    requiresQuestionAndAnswer="true"
    passwordFormat="Hashed"
    enablePasswordRetrieval="false"
    enablePasswordReset="true"
    maxInvalidPasswordAttempts="2"
    passwordAttemptWindow="1"

    />
Posted
Updated 8-Jul-12 2:44am
v2
Comments
kornakar 9-Jul-12 3:03am    
Have you debugged the code so that you're sure that the UnlockUser method actually gets called?
SASS_Shooter 11-Jul-12 15:35pm    
Have you also debugged your code to confirm that the UnlockUser method is being invoked as Administrator???? Only administrators can unlock user acccounts!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900