<commit_before><?php

namespace App\Http\Controllers;

use App\User;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Auth;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Http\Response;

class LoginController extends Controller
{
    public function postLogin(Request $request)
    {
        // Ensure arguments are present.
        if (!($request->has('username') && $request->has('password'))) {
            // Missing arguments!
            abort(400); // Bad Request
        }

        $username = $request->input('username');
        $password = $request->input('password');

        // Responses will be in JSON
        header('Content-Type: application/json');

        // Attempt login
        if (Auth::attempt(['name' => $username, 'password' => $password])) {
            // Return success response
            return json_encode(array(
                'success' => true
            ));
        } else {
            // Return failure response
            return json_encode(array(
                'success' => false
            ));
        }
    }

    public function postRegister(Request $request)
    {
        $errors = [];

        // Validate all fields have been received.
        $validator = \Validator::make($request->all(), array(
            'email' => 'required|email|max:128|unique:users,email',
            'username' => 'required|min:1|max:32|unique:users,name',
            'password' => '<PASSWORD>'
        ));

        if ($validator->fails()) {
            // Validator detected some problems.
            foreach($validator->errors()->getMessages() as $error) {
                $errors[] = $error;
            }
        }

        if (count($errors) > 0) {
            // Errors detected, generate response
            $response = new Response(json_encode([
                'status' => false,
                'errors' => $errors
            ]), 200);
            $response->header('Content-Type', 'application/json');

            return $response;
        }

        // Get input
        $email = $request->input('email');
        $username = $request->input('username');
        $password = $request->input('password');

        // Register user
        User::register($email, $username, $password);

        // Generate response
        $response = new Response(json_encode([
            'status' => true
        ]), 200);
        $response->header('Content-Type', 'application/json');

        return $response;
    }
}
<commit_msg>Reduced max username length to 20 characters<commit_after><?php

namespace App\Http\Controllers;

use App\User;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Auth;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Http\Response;

class LoginController extends Controller
{
    public function postLogin(Request $request)
    {
        // Ensure arguments are present.
        if (!($request->has('username') && $request->has('password'))) {
            // Missing arguments!
            abort(400); // Bad Request
        }

        $username = $request->input('username');
        $password = $request->input('password');

        // Responses will be in JSON
        header('Content-Type: application/json');

        // Attempt login
        if (Auth::attempt(['name' => $username, 'password' => $password])) {
            // Return success response
            return json_encode(array(
                'success' => true
            ));
        } else {
            // Return failure response
            return json_encode(array(
                'success' => false
            ));
        }
    }

    public function postRegister(Request $request)
    {
        $errors = [];

        // Validate all fields have been received.
        $validator = \Validator::make($request->all(), array(
            'email' => 'required|email|max:128|unique:users,email',
            'username' => 'required|min:1|max:20|unique:users,name',
            'password' => '<PASSWORD>'
        ));

        if ($validator->fails()) {
            // Validator detected some problems.
            foreach($validator->errors()->getMessages() as $error) {
                $errors[] = $error;
            }
        }

        if (count($errors) > 0) {
            // Errors detected, generate response
            $response = new Response(json_encode([
                'status' => false,
                'errors' => $errors
            ]), 200);
            $response->header('Content-Type', 'application/json');

            return $response;
        }

        // Get input
        $email = $request->input('email');
        $username = $request->input('username');
        $password = $request->input('password');

        // Register user
        User::register($email, $username, $password);

        // Generate response
        $response = new Response(json_encode([
            'status' => true
        ]), 200);
        $response->header('Content-Type', 'application/json');

        return $response;
    }
}

{'fraction_non_alphanumeric': 0.14271672891684686, 'fraction_numerical': 0.006683703558089247, 'mean_word_length': 1.922458357265939, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 53, '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': '2387334', 'n_tokens_mistral': 1336, 'n_tokens_neox': 1303, 'n_words': 296}