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
https://forums.phpfreaks.com/topic/58628-my-login-system/
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
https://forums.phpfreaks.com/topic/58628-my-login-system/#findComment-291158
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.