<commit_before><?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/

Route::get('/', function()
{
	return View::make('loginform');
});
Route::get('login', function()
{
    return View::make('loginform');
});
Route::post('login', function()
{
    //Handle input
    $data = Input::all();
    $rules = array(
        'key' => 'integer',
        'pin' => 'integer'
    );
    // Create a new validator instance.
    $validator = Validator::make($data, $rules);
    if ($validator->fails()) {
        return Redirect::to('/');
    }
    //Data is valid Proceed to authenticate the user
    //Get this user
    $user = DB::table('users')->where('key', $data['key'])->first();

    var_dump($user);
    /* this stuff needs to move to a controller */
    function SecureThis($pin){
        $salt = '$1$' . substr(microtime(),0,8);
        return crypt($pin, $salt);
    }
    function CheckThis($pin,$salt){
        $this_salt = '$1$' . $salt;
        return crypt($pin,$this_salt);
    }
    function ParseHash($hash){
        $hash_parts = explode('$',$hash);
        return $hash_parts;
    }
    /* this stuff needs to move to a controller */
    $stored = explode('$',$user->hash);
    $supplied_check = CheckThis($data['pin'], $stored['2']);
    $supplied = explode('$',$supplied_check);
    $user_hash = $stored['3'];
    $supplied_hash = $supplied['3'];

    if((($supplied_hash == $user_hash) && $user->isAdmin)){
        //user authenticated
        setcookie("logged_in", 1, time()+3600);  /* expires in 1 hour */
        $_SESSION['logged_in'] = 1;
        $_SESSION['ircName'] = $user->ircName;
        $_SESSION['key'] = $user->key;
        echo 'User Authenticated and is an Admin';
        //header('Location: /admin.php');
    } elseif((($supplied_hash == $user_hash) && !$user->isAdmin)){
        //user authenticated - but not admin
        setcookie("logged_in", 1, time()+3600);  /* expires in 1 hour */
        $_SESSION['logged_in'] = 1;
        $_SESSION['ircName'] = $user->ircName;
        $_SESSION['key'] = $user->key;
        echo 'User Authenticated and is a User';
        //header('Location: /user.php');
    } else {
        //login failed
        echo 'Invalide Login';
        //header('Location: /login.php?msg=' . $msg);
    }
    //Login Successful - Normal User - Proceed to /user


    //Login Successful - Admin User - Proceed to /admin
<commit_msg>Invalide - it's french, trust me, I'm a doctor<commit_after><?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/

Route::get('/', function()
{
	return View::make('loginform');
});
Route::get('login', function()
{
    return View::make('loginform');
});
Route::post('login', function()
{
    //Handle input
    $data = Input::all();
    $rules = array(
        'key' => 'integer',
        'pin' => 'integer'
    );
    // Create a new validator instance.
    $validator = Validator::make($data, $rules);
    if ($validator->fails()) {
        return Redirect::to('/');
    }
    //Data is valid Proceed to authenticate the user
    //Get this user
    $user = DB::table('users')->where('key', $data['key'])->first();

    var_dump($user);
    /* this stuff needs to move to a controller */
    function SecureThis($pin){
        $salt = '$1$' . substr(microtime(),0,8);
        return crypt($pin, $salt);
    }
    function CheckThis($pin,$salt){
        $this_salt = '$1$' . $salt;
        return crypt($pin,$this_salt);
    }
    function ParseHash($hash){
        $hash_parts = explode('$',$hash);
        return $hash_parts;
    }
    /* this stuff needs to move to a controller */
    $stored = explode('$',$user->hash);
    $supplied_check = CheckThis($data['pin'], $stored['2']);
    $supplied = explode('$',$supplied_check);
    $user_hash = $stored['3'];
    $supplied_hash = $supplied['3'];

    if((($supplied_hash == $user_hash) && $user->isAdmin)){
        //user authenticated
        setcookie("logged_in", 1, time()+3600);  /* expires in 1 hour */
        $_SESSION['logged_in'] = 1;
        $_SESSION['ircName'] = $user->ircName;
        $_SESSION['key'] = $user->key;
        echo 'User Authenticated and is an Admin';
        //header('Location: /admin.php');
    } elseif((($supplied_hash == $user_hash) && !$user->isAdmin)){
        //user authenticated - but not admin
        setcookie("logged_in", 1, time()+3600);  /* expires in 1 hour */
        $_SESSION['logged_in'] = 1;
        $_SESSION['ircName'] = $user->ircName;
        $_SESSION['key'] = $user->key;
        echo 'User Authenticated and is a User';
        //header('Location: /user.php');
    } else {
        //login failed
        echo 'Invalid Login';
        //header('Location: /login.php?msg=' . $msg);
    }
    //Login Successful - Normal User - Proceed to /user


    //Login Successful - Admin User - Proceed to /admin

{'fraction_non_alphanumeric': 0.22435195326761592, 'fraction_numerical': 0.007667031763417305, 'mean_word_length': 2.2420118343195266, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, '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': '2303064', 'n_tokens_mistral': 1694, 'n_tokens_neox': 1627, 'n_words': 437}