Jump to content

Recommended Posts

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";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/119981-solved-make-login-script-safer/
Share on other sites

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

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.