Intranet Journal

Go Back   IT Management Forum > Intranet Journal

Intranet Journal The new discussion forum for Intranet Journal readers. Leave comments and questions for IJ authors. Suggest story ideas and provide feedback.

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-27-2008, 03:44 AM
Rope Rope is offline
Registered User
 
Join Date: May 2008
Posts: 1
Login form for CMS doesn't work?

Hi all,

I've been busy with the CMS written by Peter Zeidman, and I've run into some problems. It seems like the form which is used to give $_POST['user'] and $_POST['pass'] doesn't work. I've put some extra if's into the code to see if they continue to be empty and they do.

So my question is how do I solve this? I'm new to PHP so I've got no clue at all.

I adjusted some pieces in the source for them to work. Also I know it's not a MySQL problem because the adding of articles works fine (ow and I did rename some of the tables, users instead of cmsusers, articles instead of cmsarticles, but that all works fine)

Here's the code:

Welcome.php
PHP Code:
<?php
require_once('../includes/Sentry.php');
$theSentry = new Sentry();
if (!
$theSentry->checkLogin(2) )
{
header("Location: login.php");
die();
}
?>
<html>
<head>
<title>Welcome</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
Welcome to the admin area
</body>
</html>
Login.php
PHP Code:
<?php
require_once("../includes/Sentry.php");

$sentry = new Sentry();
if (
$_POST['user'] != '')
{
    echo
"<center>Username submitted</center><br>";
    
$sentry->checkLogin($_POST['user'],$_POST['pass'],4,'welcome.php','failed.php');
}
if(
$_POST['pass'] != '')
{
    echo
"<center>Password entered</center><br>";
}
if(
$_POST['pass'] == '')
{
    echo
"<center>Password is not yet entered</center><br>";
}
if(
$_POST['user'] == '')
{
    echo
"<center>No username submitted by form</center><br>";
}

if (
$_GET['action'] == 'logout')
{
    if (
$sentry->logout())
    {
        echo
'<center>You have been logged out</center><br>';
    }
    else
        echo
'<center>No need to log out, you were never logged in</center><br>';
}
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<table width="25%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#000066">
  <tr>
    <td align="center" bgcolor="#000066"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Login</strong></font></td>
  </tr>
  <tr>
    <td bordercolor="#FFFFFF">
    <form name="form1" method="post" action="login.php">
        <p>&nbsp;User:<input type="text" name="user"></p>
        <p>&nbsp;Pass:<input type="password" name="pass">
        </font></p>
        <p align="center"><input type="submit" name="Submit2" value="Submit"></p>
      </form>
        <div align="right"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><a href="login.php?action=logout">Logout</a>&nbsp;</font></div>
    </td>
  </tr>
</table>
</body>
</html>
Sentry.php
PHP Code:
<?php
////////////////////////////////////////////////////////////////////////////////////////
// Class: sentry
// Purpose: Control access to pages
///////////////////////////////////////////////////////////////////////////////////////
class sentry {
    
    var
$loggedin = false;    //    Boolean to store whether the user is logged in
    
var $userdata;            //  Array to contain user's data
    
    
function sentry(){
        
session_start();
        
header("Cache-control: private");
    }
    
    
//======================================================================================
    // Log out, destroy session
    
function logout()
    {
        if(
$_SESSION['user'] && $_SESSION['pass'])
        {
            unset(
$this->userdata);
            
session_destroy();
            return
true;
        }
        else
            return
false;
    }

    
//======================================================================================
    // Log in, and either redirect to goodRedirect or badRedirect depending on success
    
function checkLogin($user = '',$pass = '',$group = '',$goodRedirect = '',$badRedirect = ''){

        
// Include database and validation classes, and create objects
        
require_once('DbConnector.php');
        require_once(
'Validator.php');
        
$validate = new Validator();
        
$loginConnector = new DbConnector();
        
        
// If user is already logged in then check credentials
        
if ($_SESSION['user'] && $_SESSION['pass']){

            
// Validate session data
            
if (!$validate->validateTextOnly($_SESSION['user']))
            {
            return
false;
            }
            if (!
$validate->validateTextOnly($_SESSION['pass']))
            {
            return
false;
            }

            
$getUser = $loginConnector->query("SELECT * FROM users WHERE user = '".$_SESSION['user']."' AND pass = '".$_SESSION['pass']."' AND thegroup <= ".$group.' AND enabled = 1');

            if (
$loginConnector->getNumRows($getUser) > 0){
                
// Existing user ok, continue
                
if ($goodRedirect != '') {
                    
header("Location: ".$goodRedirect."?".strip_tags(session_id())) ;
                }            
                return
true;
            }
            else
            {
                
// Existing user not ok, logout
                
$this->logout();
                return
false;
            }
            
        
// User isn't logged in, check credentials
        
}
        else
        {    
            
// Validate input
            
if (!$validate->validateTextOnly($user))
            {
            return
false;
            }
            if (!
$validate->validateTextOnly($pass))
            {
            return
false;
            }

            
// Look up user in DB
            
$getUser = $loginConnector->query("SELECT * FROM users WHERE user = '$user' AND pass = MD5('$pass') AND thegroup <= $group AND enabled = 1");
            
$this->userdata = $loginConnector->fetchArray($getUser);

            if (
$loginConnector->getNumRows($getUser) > 0){
                
// Login OK, store session details
                // Log in
                
$_SESSION["user"] = $user;
                
$_SESSION["pass"] = $this->userdata['pass'];
                
$_SESSION["thegroup"] = $this->userdata['thegroup'];
                                
                if (
$goodRedirect) {
                    
header("Location: ".$goodRedirect."?".strip_tags(session_id())) ;
                }
                return
true;

            }else{
                
// Login BAD
                
unset($this->userdata);
                if (
$badRedirect) {
                    
header("Location: ".$badRedirect) ;
                }        
                return
false;
            }
        }            
    }
}    
?>
Thanks in advance , Rope.
Reply With Quote
  #2 (permalink)  
Old 06-14-2008, 12:22 AM
marzar00 marzar00 is offline
Registered User
 
Join Date: Jun 2008
Posts: 22
Edit: See below for the fix.

Last edited by marzar00; 06-14-2008 at 08:30 AM. Reason: No longer relevant
Reply With Quote
  #3 (permalink)  
Old 06-14-2008, 12:34 AM
marzar00 marzar00 is offline
Registered User
 
Join Date: Jun 2008
Posts: 22
Here's the fix:
Creating a CMS Tutorial Help

Marzar
Reply With Quote
  #4 (permalink)  
Old 06-14-2008, 12:55 AM
marzar00 marzar00 is offline
Registered User
 
Join Date: Jun 2008
Posts: 22
Ok, third time luck for a reply. Peter has released an update to the code. The problem is:
Quote:
1. If you're using MySQL to encrypt a password, you should use the MD5 command rather than the PASSWORD command, which is written in the article.
2. The PASSWORD command requires a field of length 32 in the database. The database created in the tutorial is length 20 - thus it cuts off the encrypted password and the script cannot work.
Thats taken directly from what he has said in this post: Creating a CMS Tutorial Help

Go to that link to see what you have to do to fix this problem. I just did and mine now works a treat.

Goodluck,

Marzar
Reply With Quote
  #5 (permalink)  
Old 02-16-2009, 08:58 PM
ezwep ezwep is offline
Registered User
 
Join Date: Feb 2009
Location: Israel
Posts: 1
Marzar, very nice script.
Your script is great starting point for anyone who want start with own CMS system.
I have learn a lot, thanks.
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -5. The time now is 04:55 AM.





Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.0.0