dezkit Posted August 16, 2008 Share Posted August 16, 2008 Is it possible to make this login script even safer then it is? <?php $host="localhost"; $username=""; $password=""; $db_name="test"; $tbl_name="members"; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count==1){ session_register("myusername"); session_register("mypassword"); header("location:login_success.php"); } else { echo "Wrong Username or Password"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/119981-solved-make-login-script-safer/ Share on other sites More sharing options...
ignace Posted August 16, 2008 Share Posted August 16, 2008 well i am not trying to be rude, but that script is everything but safe, you are vulnerable to sql injection and php injection (if register_globals = on) advices: - encapsulate your db connection and its configuration variables - use prepared queries - do not only use stripslashes() but also validate it using ctype (http://be.php.net/manual/en/book.ctype.php) - do not store to much information in your session, storing a user id is more than sufficient (certainly do not store passwords in sessions) - enable full error reporting when in your development environment, disable all error reporting on production (for example create a function that when called on your development server it echo's the message and on your production server it stores it to a password protected directory on your server or under your server root Quote Link to comment https://forums.phpfreaks.com/topic/119981-solved-make-login-script-safer/#findComment-618065 Share on other sites More sharing options...
dezkit Posted August 16, 2008 Author Share Posted August 16, 2008 Thanks man! Quote Link to comment https://forums.phpfreaks.com/topic/119981-solved-make-login-script-safer/#findComment-618115 Share on other sites More sharing options...
DeanWhitehouse Posted August 16, 2008 Share Posted August 16, 2008 session_register("myusername"); session_register("mypassword"); that is depriciated i think change to $_SESSION[''] = ; Quote Link to comment https://forums.phpfreaks.com/topic/119981-solved-make-login-script-safer/#findComment-618159 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.