Login Attempt Count

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
7 years ago
Hi guys,

I'm trying to do something like this:

After the fifth attempt to login, captcha will be displayed, not before that.

I've added LoginAttemptCount property to LoginModel, and on every WrongPassword case I am increasing it by 1.

Basicly it should work, but i don't know what i'm missing.


    public partial class LoginModel : BaseNopModel
    {
        public bool CheckoutAsGuest { get; set; }

        [NopResourceDisplayName("Account.Login.Fields.Email")]
        [AllowHtml]
        public string Email { get; set; }

        public bool UsernamesEnabled { get; set; }
        [NopResourceDisplayName("Account.Login.Fields.UserName")]
        [AllowHtml]
        public string Username { get; set; }

        [DataType(DataType.Password)]
        [NopResourceDisplayName("Account.Login.Fields.Password")]
        [AllowHtml]
        public string Password { get; set; }

        [NopResourceDisplayName("Account.Login.Fields.RememberMe")]
        public bool RememberMe { get; set; }

        public bool DisplayCaptcha { get; set; }

        public int LoginAttemptCount { get; set; }
    }



    @if (Model.DisplayCaptcha && Model.LoginAttemptCount >= 5)
    {
        <div class="captcha-box">
            @Html.Raw(Html.GenerateCaptcha())
            @*<div class="g-recaptcha" data-sitekey="xxxxxx"></div>*@
        </div>
    }
7 years ago
Models don't persist.  You need to store the login attempts in something like a GenericAttribute.   The controller has to read it from the attribute to set the model property during the Login request (GET), and then sets (increments) it when attempt fails (POST). You should also set it to 0 if login is successful.
7 years ago
I've done it after I asked the question. I was just missing something.

Thanks for the answer, though.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.