stackumhi Posted September 19, 2009 Share Posted September 19, 2009 I am trying to make my login form safe(er). Is this the correct way to do this? My function: function safedata($value){ return mysql_real_escape_string(trim($value)); } My login script: <?php $_SESSION['username'] = 0; if(isset($_POST['username'])){ $username = safedata($_POST[username]); $password= safedata($_POST[password]); $password = sha1("$password"); $result = mysql_num_rows(mysql_query("SELECT * FROM ADMINS WHERE email='$username' AND password='$password'")); if($result == 1){ $_SESSION['username'] = 1; ?> <script> window.location="main.php";</script> <? } else{ echo '<strong style="color:Red">Login invalid! Please try again.</strong>'; } } ?> Link to comment https://forums.phpfreaks.com/topic/174809-security-advice-please/ Share on other sites More sharing options...
stackumhi Posted September 19, 2009 Author Share Posted September 19, 2009 I guess since none of this information is being sent to the database it does not need to be cleaned? Is the method sound for forms that DO send data to the DB? Link to comment https://forums.phpfreaks.com/topic/174809-security-advice-please/#findComment-921248 Share on other sites More sharing options...
ozestretch Posted September 19, 2009 Share Posted September 19, 2009 I guess since none of this information is being sent to the database it does not need to be cleaned? Even though it is not being inserted into the database, it is in the query itself... which is where an injection occurs! Is a common mistake to think that, but must make sure it is always made safe® when using in the query. What you have is safe.... and can do more to make it safe®, just depends where you want to draw the line. function safedata($variable ){ $variable = htmlentities($variable, ENT_QUOTES); if (get_magic_quotes_gpc()) { $variable = stripslashes($variable); } $variable = mysql_real_escape_string(trim($variable)); $variable = strip_tags($variable); $variable = str_replace("\r\n", "", $variable); return $variable; } Link to comment https://forums.phpfreaks.com/topic/174809-security-advice-please/#findComment-921321 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.