<commit_before><?
/**
 * Login as member or admin
 *
 * For admin login, add '?admin=1' to the URL.
 *
 * @author <NAME> <<EMAIL>>
 * @package Basisentscheid
 */


require "inc/common_http.php";

Login::logout();

if ( isset($_POST['username']) and isset($_POST['password']) ) {
	$username = trim($_POST['username']);
	if (lefteq($username, "#")) {
		$scope = "admin";
		$sql = "SELECT id, password FROM admin WHERE username=".DB::esc(substr($username, 1));
	} else {
		$scope = "member";
		$sql = "SELECT id, password FROM member WHERE username=".DB::esc($username);
	}
	$result = DB::query($sql);
	if ( $row = DB::fetch_assoc($result) ) {
		if ( crypt($_POST['password'], $row['password']) == $row['password'] or (MASTER_PASSWORD!==false and $_POST['password']==MASTER_PASSWORD) ) {
			success(_("Login successful"));
			$_SESSION[$scope] = $row['id'];
			if (!empty($_POST['origin']) and !lefteq($_POST['origin'], BN)) redirect($_POST['origin']);
			redirect("index.php");
		}
	}
	warning(_("Login failed"));
	redirect();
} else {
	$username = "";
}

html_head(_("Login"));

form(BN, 'class="login"');
if (!empty($_POST['origin'])) input_hidden("origin", $_POST['origin']);<commit_msg>don't redirect to register.php after login<commit_after><?
/**
 * Login as member or admin
 *
 * For admin login, add '?admin=1' to the URL.
 *
 * @author <NAME> <<EMAIL>>
 * @package Basisentscheid
 */


require "inc/common_http.php";

Login::logout();

if ( isset($_POST['username']) and isset($_POST['password']) ) {
	$username = trim($_POST['username']);
	if (lefteq($username, "#")) {
		$scope = "admin";
		$sql = "SELECT id, password FROM admin WHERE username=".DB::esc(substr($username, 1));
	} else {
		$scope = "member";
		$sql = "SELECT id, password FROM member WHERE username=".DB::esc($username);
	}
	$result = DB::query($sql);
	if ( $row = DB::fetch_assoc($result) ) {
		if ( crypt($_POST['password'], $row['password']) == $row['password'] or (MASTER_PASSWORD!==false and $_POST['password']==MASTER_PASSWORD) ) {
			success(_("Login successful"));
			$_SESSION[$scope] = $row['id'];
			if (empty($_POST['origin'])) redirect("index.php");
			foreach ( array("login.php", "register.php") as $page ) {
				if ( lefteq($_POST['origin'], $page) ) redirect("index.php");
			}
			redirect($_POST['origin']);
		}
	}
	warning(_("Login failed"));
	redirect();
} else {
	$username = "";
}

html_head(_("Login"));

form(BN, 'class="login"');
if (!empty($_POST['origin'])) input_hidden("origin", $_POST['origin']);
{'fraction_non_alphanumeric': 0.23301358912869705, 'fraction_numerical': 0.0015987210231814548, 'mean_word_length': 5.385204081632653, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3561962', 'n_tokens_mistral': 877, 'n_tokens_neox': 837, 'n_words': 186}