Sunteți pe pagina 1din 8

<link rel="shortcut icon" href="img/favicon.

ico">
<!-- end: Favicon -->
<style type="text/css">
body { background: url(img/bg-login.jpg) !important; }
</style>

</head>
<body>
<div class="container-fluid-full">
<div class="row-fluid">
<div class="row-fluid">
<div class="login-box">
<h2 align="center">Logare n panoul de
administrare</h2>
<form class="form-horizontal" action="loginaction.php" method="post">
<fieldset>
<div class="input-prepend"
title="Username">
<span class="add-on"><i
class="halflings-icon user"></i></span>
<input

type="text"

required="required" name="username" id="username" value=""

placeholder="Nume

de utilizator" autofocus />


</div>
<div class="clearfix"></div>
<div class="input-prepend"
title="Password">
<span class="add-on"><i
class="halflings-icon lock"></i></span>
<input type="password"
required="required"

name="password" id="password" value=""

placeholder="Parola" />
</div>

<div for="remember" align="center">


<input type="checkbox" name="remember"
id="remember" value="1" /> ine-m minte
</div>
<div class="clearfix"></div>
<div class="button-login">
<button
name="submit" id="login"

type="submit"

class="btn btn-primary">Login</button>
</div>
<div class="clearfix"></div>
<div id="message"></div>
</form>

</div><!--/span-->
</div><!--/row-->

</div><!--/.fluid-container-->
</div><!--/fluid-row-->
<!-- start: JavaScript-->
<script src="js/jquery-1.9.1.min.js"></script>
<script src="js/jquery-migrate-1.0.0.min.js"></script>
<script src="js/jquery-ui-1.10.0.custom.min.js"></script>
<script src="js/jquery.ui.touch-punch.js"></script>
<script src="js/modernizr.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.cookie.js"></script>
<script src='js/fullcalendar.min.js'></script>
<script src='js/jquery.dataTables.min.js'></script>
<script src="js/excanvas.js"></script>
<script src="js/jquery.flot.js"></script>
<script src="js/jquery.flot.pie.js"></script>
<script src="js/jquery.flot.stack.js"></script>
<script src="js/jquery.flot.resize.min.js"></script>
<script src="js/jquery.chosen.min.js"></script>
<script src="js/jquery.uniform.min.js"></script>
<script src="js/jquery.cleditor.min.js"></script>
<script src="js/jquery.noty.js"></script>
<script src="js/jquery.elfinder.min.js"></script>

<script src="js/jquery.raty.min.js"></script>
<script src="js/jquery.iphone.toggle.js"></script>
<script src="js/jquery.uploadify-3.1.min.js"></script>
<script src="js/jquery.gritter.min.js"></script>
<script src="js/jquery.imagesloaded.js"></script>
<script src="js/jquery.masonry.min.js"></script>
<script src="js/jquery.knob.modified.js"></script>
<script src="js/jquery.sparkline.min.js"></script>
<script src="js/counter.js"></script>
<script src="js/retina.js"></script>
<script src="js/custom.js"></script>
<!-- end: JavaScript-->
</body>
</html>

<?php
/** Include the database file */
include_once 'db/db.php';
/**
* The main class of login
* All the necesary system functions are prefixed with _
* examples, _login_action - to be used in the login-action.php file
* _authenticate - to be used in every file where admin restriction is to be
inherited etc...
* @author Swashata <swashata@intechgrity.com>
*/
class itg_admin {
/**
* Holds the script directory absolute path
* @staticvar
*/
static $abs_path;
/**
* Store the sanitized and slash escaped value of post variables
* @var array
*/
var $post = array();

/**
* Stores the sanitized and decoded value of get variables
* @var array
*/
var $get = array();
/**
* The constructor function of admin class
* We do just the session start
* It is necessary to start the session before actually storing any value
* to the super global $_SESSION variable
*/
public function __construct() {
session_start();
//store the absolute script directory
//note that this is not the admin directory
self::$abs_path = dirname(dirname(__FILE__));
//initialize the post variable
if($_SERVER['REQUEST_METHOD'] == 'POST') {
$this->post = $_POST;
if(get_magic_quotes_gpc ()) {
//get rid of magic quotes and slashes if present
array_walk_recursive($this->post, array($this,
'stripslash_gpc'));
}
}
//initialize the get variable
$this->get = $_GET;
//decode the url
array_walk_recursive($this->get, array($this, 'urldecode'));
}
/**
* Sample function to return the nicename of currently logged in admin
* @global ezSQL_mysql $db
* @return string The nice name of the user
*/
public function get_nicename() {
$username = $_SESSION['admin_login'];

global $db;
$info = $db->get_row("SELECT `nicename` FROM `user` WHERE `username`
= '" . $db->escape($username) . "'");
if(is_object($info))
return $info->nicename;
else
return '';
}
/**
* Sample function to return the email of currently logged in admin user
* @global ezSQL_mysql $db
* @return string The email of the user
*/
public function get_email() {
$username = $_SESSION['admin_login'];
global $db;
$info = $db->get_row("SELECT `email` FROM `user` WHERE `username` =
'" . $db->escape($username) . "'");
if(is_object($info))
return $info->email;
else
return '';
}
/**
* Checks whether the user is authenticated
* to access the admin page or not.
*
* Redirects to the login.php page, if not authenticates
* otherwise continues to the page
*
* @access public
* @return void
*/
public function _authenticate() {
//first check whether session is set or not
if(!isset($_SESSION['admin_login'])) {
//check the cookie
if(isset($_COOKIE['username']) && isset($_COOKIE['password'])) {
//cookie found, is it really someone from the

if($this->_check_db($_COOKIE['username'],
$_COOKIE['password'])) {
$_SESSION['admin_login'] = $_COOKIE['username'];
echo "<script>window.open('home.php','_self')</script>";
die();
}
else {
echo
"<script>window.open('index.php','_self')</script>";
die();
}
}
else {
echo
"<script>window.open('index.php','_self')</script>";
die();
}
}
}

/**
* Check for login in the action file
*/
public function _login_action() {
//insufficient data provided
if(!isset($this->post['username']) || $this->post['username'] == ''
|| !isset($this->post['password']) || $this->post['password'] == '') {
echo "<script>window.open('index.php','_self')</script>";
}
//get the username and password
$username = $this->post['username'];
$password = md5(sha1($this->post['password']));
//check the database for username
if($this->_check_db($username, $password)) {
//ready to login
$_SESSION['admin_login'] = $username;
//check to see if remember, ie if cookie

if(isset($this->post['remember'])) {
//set the cookies for 1 day, ie, 1*24*60*60 secs
//change it to something like 30*24*60*60 to remember user
for 30 days
setcookie('username', $username, time() + 1*24*60*60);
setcookie('password', $password, time() + 1*24*60*60);
} else {
//destroy any previously set cookie
setcookie('username', '', time() - 1*24*60*60);
setcookie('password', '', time() - 1*24*60*60);
}
echo "<script>window.open('home.php','_self')</script>";
}
else {
echo "<script>window.open('index.php','_self')</script>";
}
die();
}

/**
* Check the database for login user
* Get the password for the user
* compare md5 hash over sha1
* @param string $username Raw username
* @param string $password expected to be md5 over sha1
* @return bool TRUE on success FALSE otherwise
*/
private function _check_db($username, $password) {
global $db;
$user_row = $db->get_row("SELECT * FROM `user` WHERE `username`='" .
$db->escape($username) . "'");
//general return
if(is_object($user_row) && md5($user_row->password) == $password)
return true;
else
return false;
}

/**
* stripslash gpc
* Strip the slashes from a string added by the magic quote gpc thingy
* @access protected
* @param string $value
*/
private function stripslash_gpc(&$value) {
$value = stripslashes($value);
}
/**
* htmlspecialcarfy
* Encodes string's special html characters
* @access protected
* @param string $value
*/
private function htmlspecialcarfy(&$value) {
$value = htmlspecialchars($value);
}
/**
* URL Decode
* Decodes a URL Encoded string
* @access protected
* @param string $value
*/
protected function urldecode(&$value) {
$value = urldecode($value);
}
}