sleep function
Hello all!
I wanted to ask everyone what they thought about the sleep function in php. I do believe I'm going to use it for my website, but I'm really unsure how to implement it in. I wanted to use it on the login page. I googled this until I'm blue in the face and can't get anywhere. Does anyone know of a good site that shows lots of examples? Or can someone show me where to put it in a login code?
Thanks bunches!
~Amy
designingamy
Junior Poster in Training
96 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
Like I said, I want to use it for the LogIn page, so if hackers want to try to use 50 billion passwords to find the right username, or vice versa, it may take them longer than they want to wait.
Since you don't use the sleep function, I'm curious to know what you use for security. I've heard both good and bad things about the sleep function. I don't think it will hurt to use it and any additional security to try to prevent the wrong ones from entering.
~Amy
designingamy
Junior Poster in Training
96 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
Hmmm...that sounds like a good idea. But what about if a hacker has a password and then does nothing but try to figure out what the username is. How do you prevent those attacks?
~Amy
designingamy
Junior Poster in Training
96 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
Yes, but I think if it were only delayed a few seconds I don't think that most users would have a major problem with it.
I guess it could be possible to do both? Limit the # of attempts as well as using the sleep function?
~Amy
designingamy
Junior Poster in Training
96 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
Once again, hackers might keep trying the passwords, but you might want to try an approach of blocking ip's. 5 attempts at an ip with an incorrect password, record the ip in a table, and pull back from the table when user's are accessing the login page. If they match an ip in the table, disable the ability to log in or along those lines. Yes they can spoof the ip's, but it is a viable solution.
dickersonka
Veteran Poster
1,175 posts since Aug 2008
Reputation Points: 130
Solved Threads: 143
That sounds like a pretty good idea...of course they could go to any computer, but it would make it harder for them.
I am not sure exactly how to write all that php code. Can you point me into the right direction, a website perhaps, that discusess this?
I really appreciate it :)
~Amy
designingamy
Junior Poster in Training
96 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
Here's a link of how to get the ip address
http://www.plus2net.com/php_tutorial/php_ip.php
Then just set up table along the lines of
BLOCKED_IP
FAILED_LOGIN_ATTEMPTS
LAST_FAILED_TIME
When the user accesses the page, check the ip against blocked_ip, if it matches then check LAST_FAILED_TIME and FAILED_LOGIN_ATTEMPTS, if it is greater than 30 min and whatever value for FAILED_LOGIN_ATTEMPTS you choose, then display the login page, otherwise dispaly the access denied page and increment the FAILED_LOGIN_ATTEMPTS. If you allow access, delete the row for that ip. If the user types in a bad password insert or increment the FAILED_LOGIN_ATTEMPTS.
You might want to go about it a little different of a way, but there is a good start.
Thanks
dickersonka
Veteran Poster
1,175 posts since Aug 2008
Reputation Points: 130
Solved Threads: 143
Awesome...thanks bunches!
~Amy
designingamy
Junior Poster in Training
96 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
dickersonka
Veteran Poster
1,175 posts since Aug 2008
Reputation Points: 130
Solved Threads: 143
I'm trying to locate my php.ini file so I can see if the register_global are off. If it is on, is it enough to just use the $ip=@$REMOTE_ADDR; or am I still going to have to use the code if they are behind a proxy?
I'm trying to get a feel for how all of this works :)
~Amy
designingamy
Junior Poster in Training
96 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
I'm trying to locate my php.ini file so I can see if the register_global are off. If it is on, is it enough to just use the $ip=@$REMOTE_ADDR; or am I still going to have to use the code if they are behind a proxy?
I'm trying to get a feel for how all of this works :)
~Amy
Here is a related thread: http://www.daniweb.com/forums/thread82966.html
digital-ether
Nearly a Posting Virtuoso
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
The problem will be that if your users are behind the proxy, you will be blocking all of them from the same ip address without using the additional code.
If they aren't behind the proxy REMOTE_ADDR will work, otherwise you will be blocking the whole proxy for a client address inside of that proxy.
dickersonka
Veteran Poster
1,175 posts since Aug 2008
Reputation Points: 130
Solved Threads: 143
Okay, so regardless if I use the $ip=@$REMOTE_ADDR; or the $ip=$_SERVER['REMOTE_ADDR']; I should still use something to check to see if they are behind the proxy, is that right?
~Amy
designingamy
Junior Poster in Training
96 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
Yes, do the other checks first like the link showed and if they ARE EMPTY, then rely upon the REMOTE_ADDR.
dickersonka
Veteran Poster
1,175 posts since Aug 2008
Reputation Points: 130
Solved Threads: 143
Okay, so if I block the IP addresses, it's possible the hacker will have an onion router so I can't see their IP address.
If I use something to shut down the user themselves and not let them get into their account after so many wrong attempts, I may have a lot of users try to get in touch with me with complaints.
I'm understanding that there are even problems with the sleep function.
If we use all these functions at once, are we really any safer? Can we win?
~Amy
designingamy
Junior Poster in Training
96 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
It is a constant battle to keep up with security and hackers or what not.
The only thing you can do is try and stay ahead of the game.
Make users have secure passwords, if user's are complaining, make them do a captcha with email address or something along those lines. Make sure your database is secure, as far as accessibility from external ips and users. Make sure you don't directly take user input and try to issue a database command with it. Althought it may take a little more time to implement and code these strategies, it will deter many hacking attempts to begin with.
dickersonka
Veteran Poster
1,175 posts since Aug 2008
Reputation Points: 130
Solved Threads: 143