<commit_before><?php


/**
 *  If user is already logged in redirect to home page
 */
session_start();
if (isset($_SESSION["user_id"])) {
    header("Location: home.php");
    exit();
}


require_once("../config.php");
require_once(SRC_PATH."database.php");
require_once(SRC_PATH."login.register.php");

$login_error = $register_error = NULL;
$value_user = $value_email = NULL;


/**
 *  Login
 */
if (isset($_POST["submit_login"])) {

    $username = trim($_POST["username"]);
    $password = $_POST["password"];

    if (!preg_match("/^[a-zA-Z0-9-_.]{5,20}+$/", $username) && !filter_var($username, FILTER_VALIDATE_EMAIL)) {
        $login_error = "Invalid username or password!";
    }

    if (!preg_match("/^[a-zA-Z0-9-_.@$#!%&]{6,50}+$/", $password)) {
        $login_error = "Invalid username or password!";
    }

    // proceed with login
    if ($login_error == NULL) {

        $hashed_password = <PASSWORD>("<PASSWORD>",$password);
        $login_result = login($username,$hashed_password);  /* login_result is either user_id or 0 (false) */

        // valid login
        if ($login_result) {

            // log
            logLogin($login_result);

            // user session
            session_start();
            $_SESSION["user_id"] = $login_result;
            header("Location: home.php");
            exit();

        // invalid login
        } else {
            $login_error = "Invalid username or password!";
        }

    }
}


/**
 *  Register
 */
if (isset($_POST["submit_register"])) {

    $username  = trim($_POST["usernamesignup"]);
    $email     = $_POST["emailsignup"];
    $password1 = $_POST["<PASSWORD>"];
    $password2 = $_POST["passwordsignup_confirm"];

    // check passwords
    if (!preg_match("/^[a-zA-Z0-9-_.@$#!%&]{6,50}+$/", $password1) || !preg_match("/^[a-zA-Z0-9-_.@$#!%&]{6,50}+$/", $password2)) {
        $register_error = "Invalid password!";
    }
    elseif ($password1 != $password2) {
        $register_error = "Passwords do not match!";
    }

    // check email
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
        $register_error = "Invalid E-Mail address!";
    } else {
        $value_email = $email;
    }

    // check username
    if (!preg_match("/^[a-zA-Z0-9-_.]{5,20}+$/", $username)) {
        $register_error = "Invalid username!";<commit_msg>Regex updated<commit_after><?php


/**
 *  If user is already logged in redirect to home page
 */
session_start();
if (isset($_SESSION["user_id"])) {
    header("Location: home.php");
    exit();
}


require_once("../config.php");
require_once(SRC_PATH."database.php");
require_once(SRC_PATH."login.register.php");

$login_error = $register_error = NULL;
$value_user = $value_email = NULL;


/**
 *  Login
 */
if (isset($_POST["submit_login"])) {

    $username = trim($_POST["username"]);
    $password = $_POST["password"];

    if (!preg_match(REGEX_USER, $username) && !filter_var($username, FILTER_VALIDATE_EMAIL)) {
        $login_error = "Invalid username or password!";
    }

    if (!preg_match(REGEX_PASS, $password)) {
        $login_error = "Invalid username or password!";
    }

    // proceed with login
    if ($login_error == NULL) {

        $hashed_password = <PASSWORD>("<PASSWORD>",$password);
        $login_result = login($username,$hashed_password);  /* login_result is either user_id or 0 (false) */

        // valid login
        if ($login_result) {

            // log
            logLogin($login_result);

            // user session
            session_start();
            $_SESSION["user_id"] = $login_result;
            header("Location: home.php");
            exit();

        // invalid login
        } else {
            $login_error = "Invalid username or password!";
        }

    }
}


/**
 *  Register
 */
if (isset($_POST["submit_register"])) {

    $username  = trim($_POST["usernamesignup"]);
    $email     = $_POST["emailsignup"];
    $password1 = $_POST["<PASSWORD>"];
    $password2 = $_POST["<PASSWORD>"];

    // check passwords
    if (!preg_match(REGEX_PASS, $password1) || !preg_match(REGEX_PASS, $password2)) {
        $register_error = "Invalid password!";
    }
    elseif ($password1 != $password2) {
        $register_error = "Passwords do not match!";
    }

    // check email
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
        $register_error = "Invalid E-Mail address!";
    } else {
        $value_email = $email;
    }

    // check username
    if (!preg_match(REGEX_USER, $username)) {
        $register_error = "Invalid username!";
{'fraction_non_alphanumeric': 0.1785950231226602, 'fraction_numerical': 0.008588416648315349, 'mean_word_length': 2.7199017199017197, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 10, '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': '5372386', 'n_tokens_mistral': 1518, 'n_tokens_neox': 1456, 'n_words': 278}