Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
if user attempts wrong password in 3 times, then block user IP address and make unable to visit our website. and show message.

What I have tried:

i just want to do this but don't know how we can do this.
Posted
Comments
Sergey Alexandrovich Kryukov 6-Feb-16 0:04am    
Why? Sounds like an utterly bad idea? And do you understand that many addresses are virtual?
—SA
PIEBALDconsult 6-Feb-16 0:57am    
Yeah, what Sergey said.
So if you _do_ do that, be sure that the block times out after some period of time.
You could keep a database table of suspect addresses and the date/time that they last became blocked.

1 solution

You can do it...but it's a poor idea.
You can get the user IP very easily:
C#
string ip = Request.UserHostAddress;

And it's trivial to add a table you your DB which contains "banned" addresses.
But...that is going to cause more problems than it solves.
The first problem is that the IP address is not specific to a single device: it is the address of the router (or similar equipment) that connects the user device to the ISP and thus the internet - so for a company it's likely that all employees in the building will "share" the same IP address. (You can't access the internal-to-the-building IP address because that never leaves the router, and it is common to every LAN installation: nearly all of them use 192.168.x.x addresses internally. And you can't access the MAC address except in very specific circumstances which occur in a minute number of cases - and they wouldn't help because they aren't unique either, and are trivial to "spoof".
The second problem is that most users have a dynamic IP address - it is assigned by the ISP when the router connects to the broadband network - so banning it does nothing except annoy innocent users when they are assigned it later! And to get a new IP is generally simple: turn off your router and wait a short period defined by the ISP and you'll get a new one when you restart it.

I wouldn't do it. Instead, I'd block the username and send an email to the registered email address with a link to "unblock" it (which requires the valid password).
 
Share this answer
 

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