开发者

Lock out users after three unsuccessful attempts without using a database

I want to lock o开发者_如何学运维ut my users after three unsuccessfull attempts without using a database.

I was trying:

public int loginAttempts()
{
    if (!(ViewData["loginAttempts"] == null))
    {
        ViewData["loginAttempts"] = int.Parse(ViewData["loginAttempts"].ToString()) + 1;
        return int.Parse(ViewData["loginAttempts"].ToString());
    }          
    else
    {
        ViewData["loginAttempts"] = 1;
        return 1;
    }
}

But it always returns 1. What modifications do I need to make?


You'd need to store this in the session, not view data. View data is sent to the view and is not persisted between requests.

public int loginAttempts()
{
    if (!(Session["loginAttempts"] == null))
    {
        Session["loginAttempts"] = int.Parse(Session["loginAttempts"].ToString()) + 1;
        return int.Parse(Session["loginAttempts"].ToString());
    }          
    else
    {
        Session["loginAttempts"] = 1;
        return 1;
    }
}


Use Session state variables.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜