<commit_before><?php
    $dbusername = 'geofit';
    $dbpass = '<PASSWORD>';
    $dbhost = 'localhost';
    $dbname = 'geofit';

    $connection = mysql_connect($dbhost, $dbusername, $dbpass);
    if (!$connection) {
        die('Could not connect: ' . mysql_error());
    }
    $dbcheck = mysql_select_db($dbname);
    if (!$dbcheck) {
        die(mysql_error());
    }

    /**
     * Try to login with given username and password.
     *
     * @param String $username The user name.
     * @param String $password The password.
     *
     * @return boolean True if the username and password exist in the login
     *                 table in the database.
     */
    function login($username, $password) {
        $qRes = mysql_query(
                'SELECT password FROM login where username=\''.$username.'\'');
        if (mysql_num_rows($qRes) > 0) {
            $res = mysql_fetch_array($qRes);
            if ($res[0] == $password) {
                return true;
            }
        }
        return false;
    }

    /**
     * Try to register with given username and password.
     *
     * @param String $username The user name.
     * @param String $password The password.
     *
     * @return boolean True if the username and password have been successfully
     *                 inserted into the login table.
     */
    function register($username, $password) {
        return mysql_query(
                'INSERT INTO login VALUES (\''.$username.'\', \''.$password.'\')');
    }

    /**
     * Try to remove the account with given username.
     *
     * @param String $username The user name.
     *
     * @return boolean True if the user record have been successfully removed
     *                 from the login table.
     */
    function remove($username) {
        return mysql_query(
                'DELETE FROM login WHERE username=\''.$username.'\'');
    }

    $ajaxResponce = Array(
            true => 'success',
            false => 'fail'
        );

    switch ($_POST['func']) {
        case 'login': 
            echo $ajaxResponce[login($_POST['username'], $_POST['password'])];
            break;
        case 'register': 
            echo $ajaxResponce[register($_POST['username'], $_POST['password'])];
            break;
        case 'remove':
            echo $ajaxResponce[remove($_POST['username'])];
    }
?><commit_msg>Add comment to the php file.<commit_after><?php

/**
 * This program communicates with mySQL database. It provides functions to
 * responce mySQL queries.
 *
 * @version 1.0
 */

/**
 * The username we used to access mySQL database system.
 *
 * @var string
 * @access private
 */
var $dbusername = 'geofit';

/**
 * The password we used to access mySQL database system.
 *
 * @var string
 * @access private
 */
var $dbpass = '<PASSWORD>';

/**
 * The host of database we connected.
 *
 * @var string
 * @access private
 */
var $dbhost = 'localhost';

/**
 * The name of database we connected.
 *
 * @var string
 * @access private
 */
var $dbname = 'geofit';

/**
 * The connection attempt with mySQL database system.
 *
 * @var boolean
 * @access private
 */
var $connection = mysql_connect($dbhost, $dbusername, $dbpass);
if (!$connection) {
    die('Could not connect: ' . mysql_error());
}

/**
 * The connection attempt with database.
 *
 * @var boolean
 * @access private
 */
var $dbcheck = mysql_select_db($dbname);
if (!$dbcheck) {
    die(mysql_error());
}

/**
 * Try to login with given username and password.
 *
 * @param String $username The user name.
 * @param String $password The password.
 *
 * @return boolean True if the username and password exist in the login
 *                 table in the database.
 */
function login($username, $password) {
    $qRes = mysql_query(
            'SELECT password FROM login where username=\''.$username.'\'');
    if (mysql_num_rows($qRes) > 0) {
        $res = mysql_fetch_array($qRes);
        if ($res[0] == $password) {
            return true;
        }
    }
    return false;
}

/**
 * Try to register with given username and password.
 *
 * @param String $username The user name.
 * @param String $password The password.
 *
 * @return boolean True if the username and password have been successfully
 *                 inserted into the login table.
 */
function register($username, $password) {
    return mysql_query(
            'INSERT INTO login VALUES (\''.$username.'\', \''.$password.'\')');
}

/**
 * Try to remove the account with given username.
 *
 * @param String $username The user name.
 *
 * @return boolean True if the user record have been successfully removed
 *                 from the login table.
 */
function remove($username) {
    return mysql_query(
            'DELETE FROM login WHERE username=\''.$username.'\'');
}

/**
 * The stringified boolen value for responce ajax request.
 *
 * @var array
 * @access private
 */
var $ajaxResponce = Array(
        true => 'success',
        false => 'fail'
    );

/*
 * This statement is used for responce ajax request.
 */
switch ($_POST['func']) {
    case 'login': 
        echo $ajaxResponce[login($_POST['username'], $_POST['password'])];
        break;
    case 'register': 
        echo $ajaxResponce[register($_POST['username'], $_POST['password'])];
        break;
    case 'remove':
        echo $ajaxResponce[remove($_POST['username'])];
}
?>
{'fraction_non_alphanumeric': 0.13561847988077497, 'fraction_numerical': 0.0011177347242921013, 'mean_word_length': 2.353529044347283, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, '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': '7333578', 'n_tokens_mistral': 1513, 'n_tokens_neox': 1494, 'n_words': 493}