Hawk
Posts: 0
Joined: Mon Aug 04, 2014 11:23 am

Block user after three failed login attempt

I followed the tutorial [1] to build a user registeration and worked fine. Now I am trying to add feature such that when the user insert wrong username or password for three times, s/he will be blocked.

What I've tried is as follows:
1) LSV at login page load (errorCount)
2) In login_service, at "error" event, I've added:

alert("Incorrect username or password");
if (localStorage.getItem("errorCount") = 3){
alert("account is blocked!");}
localStorage.setItem("errorCount", errorCount++);

3) "success" event:

if (localStorage.getItem("errorCount") = 3){
alert("account is blocked!");}
else if (localStorage.getItem("accepted") !== "true")
{Apperyio.navigateTo("dg110_Disclaimer"); }
else {Apperyio.navigateTo("pg200_HomePage");}

However, no matter how many times the user insert wrong password, the message of "account is locked" is not showing and the user still can try again and again. I've used Weinre debugging and found "errorCount" remains zero. Is there anything wrong with my logic above? I deeply appreciate your help

[1] http://devcenter.appery.io/tutorials/...

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Block user after three failed login attempt

Hello Hawk,

Please note that LSV keeps data in the string format, so you should apply to it the same way.
Please replace
preif (localStorage.getItem("errorCount") = 3){
alert("account is blocked!");}
localStorage.setItem("errorCount", errorCount++);/pre
with
prevar errorCount = parseInt(localStorage.getItem("errorCount"));
if (errorCount = 3){
alert("account is blocked!");
}
localStorage.setItem("errorCount", errorCount++);/pre

Hawk
Posts: 0
Joined: Mon Aug 04, 2014 11:23 am

Block user after three failed login attempt

Thanks for pointing out LSV format. I updated the script with the one you posted. Unfortunately, errorCount remains zero in (Weinre debugging) no matter how many time failed login attempts occured!

When I set the errorCount on page load, the set the value to '0'. When I tried to leave it blank, the value of errorCount become NaN after first failed login attempt.

In browser debbuger, I get the following error in consol window:
GET https://api.appery.io/rest/1/db/login... 404 (Not Found)

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Block user after three failed login attempt

Hawk,

You should replace
prevar errorCount = parseInt(localStorage.getItem("errorCount"));/pre
with
prevar errorCount = parseInt(localStorage.getItem("errorCount")) || 0;/pre

Hawk
Posts: 0
Joined: Mon Aug 04, 2014 11:23 am

Block user after three failed login attempt

Hi Evgene, I tried that, but the value of errorCount remained Zero after the failed login attempt!

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Block user after three failed login attempt

Hi Hawk,

Could you please post screenshots so we could see on what event you run the code?

Hawk
Posts: 0
Joined: Mon Aug 04, 2014 11:23 am

Block user after three failed login attempt

Hi,

First snapshot shows all events on the login page
1) You can see, i set LSV on page load event and the value is 0.
2) Then Login button ( mobilebutton_15) is invoking a service "login_test"
3) In the service, login_test, I have two events (success & error)
4) Error is the event I am testing now
5) You can see the script under this event

Image

Image

Image

Many thanks in advance!

obullei
Posts: 0
Joined: Thu Jun 05, 2014 12:17 am

Block user after three failed login attempt

Hello!

Please provide us with a public app link (http://devcenter.appery.io/documentat...).

Hawk
Posts: 0
Joined: Mon Aug 04, 2014 11:23 am

Block user after three failed login attempt

Hi, here is the link: http://appery.io/app/mobile-frame?src...

regards,

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Block user after three failed login attempt

Hi Hawk,

Here is a right code for you:

pre

var isUserNameBlank = Apperyio("mobiletextinput_5").val();
var isPasswordBlank = Apperyio("mobiletextinput_7").val();

if (isUserNameBlank === '' && isPasswordBlank !== '') {
alert("Enter your username!");
} else if (isUserNameBlank !== '' && isPasswordBlank === '') {
alert("Enter your password!");
} else if (isUserNameBlank === '' && isPasswordBlank === '') {
alert("Enter your username and password!");
} else {
alert("Your login credentials are invalid. Please try again!");
}

//var errorCount = parseInt(localStorage.getItem("errorCount"));
var errorCount = parseInt(localStorage.getItem("errorCount")) || 0;
console.log(errorCount);
if (errorCount = 3) {
alert("account is blocked!");
}
errorCount = errorCount + 1;
localStorage.setItem("errorCount", errorCount);

/pre

The problem was in code:

pre

localStorage.setItem("errorCount", errorCount++);

/pre

errorCount++ before returns current value and then make increment. That called postincrement.

You can learn more about it here: http://javascript.about.com/od/hintsa...

Regards.

Return to “Issues”