2017 © Pedro Peláez
 

library validate-laravel-auth

Custom Laravel 4 Auth Validator service provider composer package

image

hampel/validate-laravel-auth

Custom Laravel 4 Auth Validator service provider composer package

  • Friday, May 22, 2015
  • by hampel
  • Repository
  • 0 Watchers
  • 0 Stars
  • 89 Installations
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 13 Versions
  • 0 % Grown

The README.md

Hampel Laravel Auth Validator

Custom Auth Validators for Laravel 4, (*1)

By Simon Hampel., (*2)

Notes

I have decided not to update this package to work with Laravel 5 - this functionality is provided by the built-in Auth Controller and avoids the complexity of trying to authenticate users inside a validation rule., (*3)

For more information, have a look at the Laravel 5 trait AuthenticatesAndRegistersUsers, (*4)

:::php
/**
 * Handle a login request to the application.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return \Illuminate\Http\Response
 */
public function postLogin(Request $request)
{
    $this->validate($request, [
        'email' => 'required', 'password' => 'required',
    ]);
    $credentials = $request->only('email', 'password');
    if ($this->auth->attempt($credentials, $request->has('remember')))
    {
        return redirect()->intended($this->redirectPath());
    }
    return redirect($this->loginPath())
                ->withInput($request->only('email', 'remember'))
                ->withErrors([
                    'email' => 'These credentials do not match our records.',
                ]);
}

This effectively achieves the same result with no coding required by us!, (*5)

However, I do recognise that there are other uses for the validation library, so if there is a use-case for including auth functionality in the validation library which I haven't considered, please let me know and I'll revisit releasing a L5 version of this package., (*6)

Installation

The recommended way of installing Hampel Laravel Auth Validator is through Composer:, (*7)

Require the package via Composer in your composer.json, (*8)

:::json
{
    "require": {
        "hampel/validate-laravel-auth": "1.3.*"
    }
}

Run Composer to update the new requirement., (*9)

:::bash
$ composer update

The package is built to work with the Laravel 4 Framework., (*10)

Open your Laravel config file config/app.php and add the service provider in the $providers array:, (*11)

:::php
"providers" => array(

    ...

    "Hampel\Validate\LaravelAuth\ValidateServiceProvider"

),

Usage

This package adds an additional validator for Laravel 4 - refer to Laravel Documentation - Validation for general usage instructions., (*12)

auth:credential_column1,credential_value1,credential_column2,credential_value2,...__, (*13)

The field under validation must be a password, which is combined with the supplied credential column names and values and then passed to Auth::validate to check whether they are a valid password/credential combination., (*14)

At least two parameters to the auth rule are required (if less than two are provided, the rule will always fail)., (*15)

  1. credential_column1: name of the first credential column field, eg: 'username' ('user_login' in WordPress), or 'email', ('user_email' in WordPress).
  2. credential_value1: value of the first credential to locate in the first credential column
  3. credential_column2: name of the second credential column
  4. credential_value2: value of the second credential
  5. ...

In this way, multiple credentials can be specified to validate a user against (eg locate a user using both username and email)., (*16)

Example

:::php
$username_field = "user_login";

$username = Input::get('username');
$password = Input::get('password');

$user_table = Config::get('auth.table');

$userdata = array(
    'username' => $username,
    'password' => $password
);

// Declare the rules for the form validation.
$rules = array(
    'username' => array('required', "exists:{$user_table},{$username_field}"),
    'password' => array('required', "auth:{$username_field},{$username}")
);

// Validate the inputs.
$validator = Validator::make($userdata, $rules);

// Check if the form validates with success.
if ($validator->passes())
{
    dd("passes");
}
else
{
    dd("fails");
}

The Versions

22/05 2015

dev-master

9999999-dev https://bitbucket.org/hampel/validate-laravel-auth

Custom Laravel 4 Auth Validator service provider composer package

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel authentication validation

22/05 2015

1.3.1

1.3.1.0 https://bitbucket.org/hampel/validate-laravel-auth

Custom Laravel 4 Auth Validator service provider composer package

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel authentication validation

08/07 2014

1.3.0

1.3.0.0 https://bitbucket.org/hampel/validate-laravel-auth

Custom Laravel 4 Auth Validator service provider composer package

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel authentication validation

06/06 2014

1.2.4

1.2.4.0 https://bitbucket.org/hampel/validate-laravel-auth

Custom Laravel 4 Auth Validator service provider composer package

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel authentication validation

17/12 2013
17/12 2013
15/12 2013
13/12 2013
21/10 2013
15/10 2013
14/10 2013
13/10 2013
27/09 2013

1.0.0

1.0.0.0 https://bitbucket.org/hampel/validate-laravel-auth

Custom Laravel 4 Auth Validator service provider composer package

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel authentication validation