mhmcr /login.php

Language PHP Lines 49
MD5 Hash f79dc6cdf22b1ba92a7b4c10ca1be4f4 Estimated Cost $1,041 (why?)
Repository https://bitbucket.org/mhell/mhmcr.git View Raw File View Project SPDX
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
require_once('system.php');
include_once('inc/pass.inc.php');
function randString( $pass_len = 50 )
{
    $allchars = "abcdefghijklmnopqrstuvwxyz0123456789";
    $string = "";
    mt_srand( (double) microtime() * 1000000 );
    for ( $i=0; $i<$pass_len; $i++ )
	$string .= $allchars{ mt_rand( 0, strlen( $allchars )-1 ) };
    return $string;
}

if (isset($_POST['login']) and empty($user)) {
	$name=mysql_real_escape_string($_POST['login']);
	$pass=mysql_real_escape_string($_POST['password']);
	$result = mysql_query("SELECT ".$db['users']['password']." FROM ".$db['tables']['users']." WHERE ".$db['users']['username']."='$name'"); 
	$line = mysql_fetch_array( $result ); 
	if ($line == NULL or !checkPass($line[$db['users']['password']],$pass)) {
		mysql_close( $link );
		header("Location: ".mgetOpt('url-base')); 
		exit;
	}
	$user = new User($name,$db['users']['username']);
	if ($user->lvl() <= 0) {
		unset($user);
		mysql_close( $link );
		header("Location: ".mgetOpt('url-base')."?e=1"); 
		exit; 
	}
	if (!isset($_SESSION)) 
		session_start();
	$tmpID = randString( 15 );
	if (isset($_POST['ipcheck'])) 
		$tmpID = 'ipcheck_'.$tmpID;
	setcookie( "PRTCookie1", "$tmpID",time() + 60 * 60 * 24 * 30 * 12, '/');
	$user->login($tmpID,GetRealIp());
	$_SESSION['user_id'] = $user->id();
	$_SESSION['user_name'] = $user->name();
	$_SESSION['ip'] = $user->ip();
	header("Location: ".mgetOpt('url-base'));
}

if (isset($_GET['out']) and $user) {
	$user->logout();
	header("Location: ".mgetOpt('url-base'));
	exit;
}
?>
Back to Top