Location: PHPKode > projects > CorePHPAlbum > cpa-2.0.2/login.php
<?php

/*   ========================================================
     =                                                      =
     = corePHPAlbum - web-based photo gallery               =
     =                                                      =
     = Official code                                        =
     = file release 2.0.2                                   =
     =                                                      =
     = http://sourceforge.net/projects/corephpalbum         =
     =                                                      =
     ======================================================== */

require_once('_res/admin/lang.php');
require_once('_res/admin/tools.php');
require_once('_res/sources/authentication.php');
require_once('_res/sources/utilities.php');

// Initialization
//
$starttime = float_microtime();

switch($_GET['act'])
{
	case 'setup':
		setup();
		break;
	case 'setup_cgi':
		setup_cgi();
		break;
	case 'login_cgi':
		login_cgi();
		break;
	case 'quit':
		logout();
		login();
		break;
	default:
		login();
		break;
}

exit();


function setup()
{
	$fp = @fopen("_res/admin/setup00.html", "r");
	$data = @fread($fp, filesize("_res/admin/setup00.html"));
	@fclose($fp);
	
	format_adminpage($data, commandbar(-10));
}

function setup_cgi()
{
	$success = FALSE;
	$raw_login = stripslashes($_POST['loginname']);
	$raw_pass = stripslashes($_POST['password']);
	if ($raw_login != '' && $raw_pass != '') {
		$hashedlogin = str_replace('$', '\$', crypt($raw_login));
		$hashedpass  = str_replace('$', '\$', crypt($raw_pass));

		$passfile = '_config/password.php';
		$fp = @fopen($passfile, "w");
		$success = ($fp === FALSE ? FALSE : TRUE);
	}
	
	if ($success) {
		fwrite($fp , "<?php\n");
		fwrite($fp , "\$loginname = '" . $hashedlogin . "';\n");
		fwrite($fp , "\$password  = '" . $hashedpass . "';\n");
		fwrite($fp , "?>\n");
		fclose($fp);

		// Check if write successful
		$loginname = NULL;
		$password = NULL;
		@include('_config/password.php');
		if ( $loginname == $hashedlogin && $password == $hashedpass ) {
			redirect_to_url('login.php');
		} else {
			$success = FALSE;
		}
	}
	
	if (!$success) {
		$fp = @fopen("_res/admin/setup01.html", "r");
		$data = @fread($fp, filesize("_res/admin/setup01.html"));
		@fclose($fp);
		format_adminpage($data, commandbar(-10));
	}

}

function login()
{
	$loginname = NULL;
	$password = NULL;
	@include('_config/password.php');
	if ( $loginname == NULL || $password == NULL ) {
		redirect_to_url('login.php?act=setup');
	}

	// Login page
	$fp = @fopen("_res/admin/login00.html", "r");
	$data = @fread($fp, filesize("_res/admin/login00.html"));
	@fclose($fp);
	format_adminpage($data, commandbar(-10));
}

function login_cgi()
{
	$logged_in = check_password($_POST['loginname'], $_POST['password']);
	if ($logged_in) {
		redirect_to_url('admin.php');
	} else {
		$fp = @fopen("_res/admin/login01.html", "r");
		$data = @fread($fp, filesize("_res/admin/login01.html"));
		@fclose($fp);
		format_adminpage($data, commandbar(-10));

		//redirect_to_url('login.php');
	}
}

?>
Return current item: CorePHPAlbum