Jump to content

My Login System


tamumech

Recommended Posts

Hi all.

 

I wanted to run this by you guys to make sure I'm not making any huge security mistakes.  As suggested before, each page generates a random token that is required by the next page.

 

My Login page:

<?php

// If it hasn't been submitted
if ( !$_POST[login_submit] )
{
include ("login_form.inc");
die();
}

// Check for blanks
foreach ($_POST as $input )
{
if ( $input == "" )
	{
	echo "You must enter a Username and Password.";
	include ("login_form.inc");
	die();
	}
}

// Encrypt password
$crypt_pass = md5($_POST[password]);

// Verify user
include("today.inc");
$connect = mysql_connect($host, $user, $pass) or die('Failure to connect to Database.  Please contact us at customer support');
$db_connect = mysql_select_db($db) or die ('Failure to select Database.  Please contact us at customer support');
$select = "SELECT email FROM schools WHERE email = '$_POST[email]' AND password = '$crypt_pass'";
$result = mysql_query($select) or die('Could not execute query');
$num_rows = mysql_num_rows($result);
// Start session and redirect
if ( $num_rows > '0' )
	{
	session_start();
	session_regenerate_id();
	$_SESSION['auth'] = TRUE;
	$token = md5(uniqid(rand(),TRUE));
	$_SESSION['token'] = $token;
	header("Location: http://www.website.com?token=$token");	
	}
// get outta my house	
else
	{
	echo "Invalid Username or Password.";
	include ("login_form.inc");
	die();		
	}

?>

 

And the includes file at the top of every restricted page:

<?php 
session_start();
if ( $_SESSION['auth'] != "TRUE" || $_SESSION['token'] != $_GET['token'] )
{
header('Location: login.php');
die();
}
$token = md5(uniqid(rand(),TRUE));
$_SESSION['token'] = $token;
?>

 

An example page:

<?php 
include("top.inc");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<a href="player_counter.php<?php echo "?token=$token" ?>">Click Here</a>
<p>Members Only</p>
</body>
</html>

Link to comment
Share on other sites

you may also want to do something like this before sending data to your sql

 

 

//trims and strips tags and escapes fields

$checkuser = mysqli_real_escape_string($mysqli,trim(strip_tags($_POST['username'])));

$checkpassword = mysqli_real_escape_string($mysqli,trim(strip_tags($_POST['password'])));

Link to comment
Share on other sites

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.