Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi folk's

Can any one help me out ,i done coding for if attempts 3 invalid user attempts by taking int static count variable,in that i have one drawback ,if one user made 2 invalid attempts ,and other user made 1st time invalid attempt and this account is blocking ,How can i rectify this problem can any one help me....

I placing my code below please check it out yar and tell me with one is the better option .....

C#
static int count = 0;
    public void  count_log()//this my user count static function............
    {
        BAL_ClassLibrary.Rcm_service.LoginEntities get_login_details = login_values();
        if (count >2)
        {
            Loginbal objbal=new Loginbal();
             objbal.account_block(get_login_details);
             ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "Result", "alert('*Your Account is blocked')", true);
               count = 0;

        }
        else
        {
            ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "Result", "alert('*Invalied username or password')", true);
            count++;
        }


I am calling this function, when user made invalid user attempt to login...
and i incrementing the count value.....
Posted
Updated 26-Sep-12 2:46am
v3
Comments
Hadi Basiri 26-Sep-12 8:41am    
You can use of Session.
Session["Count"]

Static is working as expected and its certainly not for what you are trying to do. Scope of static members is for app domain, that means every user has a access/scope to static member. So that its value gets influenced/changed by all the users.

In your case you need user specific login-attepmt count. You may use Sessions for this. Have a look at below links for information on "Asp.Net Sessions".

http://msdn.microsoft.com/en-us/library/ms178581(v=vs.100).aspx

http://msdn.microsoft.com/en-us/library/ms972429.aspx

Have a look at below links for "ASP.NET State Management".

ASP.NET State Management Overview

ASP.NET State Management Recommendations

Beginners Introduction to State Management Techniques in ASP.NET
 
Share this answer
 
You can add an extra column named "FailedLoginAttempts" in your user table, and update the value after each login attempt. After successfull login you should reset the column to 0 again.

But you need to keep in mind two important scenario...
1. if user puts wrong/ invalid user name how will you maintain that ?
2. anyone who knows someone other's username can block his/her account by trying again and again.

Hope this will help you...
 
Share this answer
 
Hello ,

first remove static declaration which scrudup your logic. please refer corrected below one
C#
    public void  count_log()//this my user count static function............
    {
        BAL_ClassLibrary.Rcm_service.LoginEntities get_login_details = login_values();
 int count = Functions.ToInt32(webSession.GetVariable("LoginCount"))
        if (count >2)
        {
            Loginbal objbal=new Loginbal();
             objbal.account_block(get_login_details);
             ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "Result", "alert('*Your Account is blocked')", true);
               count = 0;
 
        }
        else
        {
            ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "Result", "alert('*Invalied username or password')", true);
 
            count = Convert.ToInt32(webSession.GetVariable("LoginCount"));
                            count += 1;

                            webSession.SetVariable("LoginCount", count )
;
        }

Function is user define but you can use Convert.Toint to achieve it.

Please let us know if any.
 
Share this answer
 
v3
Comments
mahesh.b.p.c 27-Sep-12 0:20am    
Function isit userdefined function,or predefined fun..

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