<commit_before><?
	//------------------------------------------------------------------------------------------
	function render_login() {
	//------------------------------------------------------------------------------------------
		global $LOGIN;
		
		echo <<<END
		<h1>Login</h1>
		<form class="form-horizontal" role="form" method="post">
		  <div class="form-group">
			<label class="control-label col-sm-2" for="username">{$LOGIN['form']['username']}:</label>
			<div class="col-sm-3">
			  <input type="text" class="form-control" name="username" id="username">
			</div>
		  </div>
		  <div class="form-group">
			<label class="control-label col-sm-2" for="password">{$LOGIN['form']['password']}:</label>
			<div class="col-sm-3"> 
			  <input type="password" class="form-control" name="password" id="password">
			</div>
		  </div>
		  <div class="form-group"> 
			<div class="col-sm-offset-2 col-sm-10">
			  <input type="submit" class="btn btn-primary" value="Submit">
			</div>
		  </div>
		</form>
END;
	}
	
	//------------------------------------------------------------------------------------------
	function verify_password($plain, $hash) {
	//------------------------------------------------------------------------------------------
		global $LOGIN;
		if(isset($LOGIN['password_verify_func']))
			return $LOGIN['password_verify_func']($plain, $hash);
		
		// default: simply compare
		if(!isset($LOGIN['password_hash_func']))
			return $hash == $plain;		
		return $hash == $LOGIN['password_hash_func']($plain);
	}

	//------------------------------------------------------------------------------------------
	function process_login() {
	//------------------------------------------------------------------------------------------
		global $LOGIN;
		
		if(!isset($_POST['username']) || !isset($_POST['password']))
			return proc_error('Please provide username and password.');
		
		$sql = sprintf('SELECT * FROM %s WHERE %s = ?',
			db_esc($LOGIN['users_table']), 
			db_esc($LOGIN['username_field']));
		
		$db = db_connect();
		if($db === false)
			return proc_error("Invalid database configuration.");
			
		$stmt = $db->prepare($sql);
		if($stmt === false)
			return proc_error("Invalid login parameters.", $db);
		
		if($stmt->execute(array($_POST['username'])) === false)
			return proc_error("Invalid login parameters.", $db);
		
		$error_msg = "Invalid {$LOGIN['form']['username']} and/or {$LOGIN['form']['password']}.";
		
		if(($user = $stmt->fetch(PDO::FETCH_ASSOC)) === false)
			return proc_error('FUCK'.$error_msg);
		
		if(!verify_password($_POST['password'], $user[$LOGIN['password_field']]))<commit_msg>remove profanity issues :-)<commit_after><?
	//------------------------------------------------------------------------------------------
	function render_login() {
	//------------------------------------------------------------------------------------------
		global $LOGIN;
		
		echo <<<END
		<h1>Login</h1>
		<form class="form-horizontal" role="form" method="post">
		  <div class="form-group">
			<label class="control-label col-sm-2" for="username">{$LOGIN['form']['username']}:</label>
			<div class="col-sm-3">
			  <input type="text" class="form-control" name="username" id="username">
			</div>
		  </div>
		  <div class="form-group">
			<label class="control-label col-sm-2" for="password">{$LOGIN['form']['password']}:</label>
			<div class="col-sm-3"> 
			  <input type="password" class="form-control" name="password" id="password">
			</div>
		  </div>
		  <div class="form-group"> 
			<div class="col-sm-offset-2 col-sm-10">
			  <input type="submit" class="btn btn-primary" value="Submit">
			</div>
		  </div>
		</form>
END;
	}
	
	//------------------------------------------------------------------------------------------
	function verify_password($plain, $hash) {
	//------------------------------------------------------------------------------------------
		global $LOGIN;
		if(isset($LOGIN['password_verify_func']))
			return $LOGIN['password_verify_func']($plain, $hash);
		
		// default: simply compare
		if(!isset($LOGIN['password_hash_func']))
			return $hash == $plain;		
		return $hash == $LOGIN['password_hash_func']($plain);
	}

	//------------------------------------------------------------------------------------------
	function process_login() {
	//------------------------------------------------------------------------------------------
		global $LOGIN;
		
		if(!isset($_POST['username']) || !isset($_POST['password']))
			return proc_error('Please provide username and password.');
		
		$sql = sprintf('SELECT * FROM %s WHERE %s = ?',
			db_esc($LOGIN['users_table']), 
			db_esc($LOGIN['username_field']));
		
		$db = db_connect();
		if($db === false)
			return proc_error("Invalid database configuration.");
			
		$stmt = $db->prepare($sql);
		if($stmt === false)
			return proc_error("Invalid login parameters.", $db);
		
		if($stmt->execute(array($_POST['username'])) === false)
			return proc_error("Invalid login parameters.", $db);
		
		$error_msg = "Invalid {$LOGIN['form']['username']} and/or {$LOGIN['form']['password']}.";
		
		if(($user = $stmt->fetch(PDO::FETCH_ASSOC)) === false)
			return proc_error($error_msg);
		
		if(!verify_password($_POST['password'], $user[$LOGIN['password_field']]))
{'fraction_non_alphanumeric': 0.37667991671398826, 'fraction_numerical': 0.0034071550255536627, 'mean_word_length': 1.8196371398078977, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 55, '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': '3043716', 'n_tokens_mistral': 1649, 'n_tokens_neox': 1432, 'n_words': 264}