Show the image verify code when login 3 times

Hi guy,

can anyone give me some idea how to set the condition to show verify code when user try to login for 3 times.

Thank. =)

You must have table that will contain ip_address(varchar 20), invalid_login_date(datetime) and counter(int).

So, in your login action, if user login is unsuccessful, you must insert new row into invalid login table, or update existing row depending on period from last invalid login try from this ip(I usually set this to 30 minutes).

In case your logged successfully, you can either delete complete row for this ip address, or just reset counter to 0.

Additionally, after 5 invalid logins, you can block this ip, for some period.

The problem with this approach is, if there are many users sharing same ip address. In this case, you might want to add additional field username to invalid login table, and using it in condition.

This could be done by sessions too, but it is less secure, as user can clear cookies in every request.

hi Ivica,

thank for reply. Is that any resource and information inside the yii tutorial that can refer. I still beginner.

thank… =)

Well I don’t know if there are some wiki articles or forum post, you can try to search. I had to implement similar request few days ago, so I know what you need to do.

The best is to get familiar with authentication process, so you will know where you need to add code, for invalid login, where to reset counters and so on.

Of course this might sound scary if you are new to yii, but we all was in similar situation, when started with Yii!