2017 © Pedro Peláez
 

library multicolumnauth

Makes it possible to log in with both a username and / or email

image

puz/multicolumnauth

Makes it possible to log in with both a username and / or email

  • Friday, January 29, 2016
  • by Molteber
  • Repository
  • 2 Watchers
  • 1 Stars
  • 4 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Laravel MultiColumnAuth

Ever felt like you need to allow both a username and email field? Then you're in luck!
Puz MultiColumnAuth enables you to allow your users to use whatever userfield they want to when they log in!, (*1)

Installation

composer require puz/multicolumnauth

You will need to update your config/app.php by adding the service provider to your application.
Add this under the provider section: Puz\MultiColumnAuth\ServiceProvider::class, (*2)

To configure your fields and columns you'll need to add my configuration files. Simply do this by running the artisan command php artisan vendor:publish, (*3)

The last thing you have to do now, is to replace the current Authorization trait. In the default AuthController class, you will see that laravel have included use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;. If you're still using both the authentication and registration of users, simply change this to: use Puz\MultiColumnAuth\AuthenticatesAndRegistersUsers;. If you don't need registration, simply change it to use Puz\MultiColumnAuth\AuthenticatesUsers;, or do the same if you have a custom registration trait maybe and need to include this AuthenticatesUsers in your custom class. In short, there are two available trais:
Puz\MultiColumnAuth\AuthenticatesAndRegistersUsers
Puz\MultiColumnAuth\AuthenticatesUsers, (*4)

How to

Select which columns I can use for login
In your newly created config file from php artisan vendor:publish located in config/puz/multicolumnauth.php, there exists a array with a key named columns. This key takes an array as a value with the columns you want the users to log in with. Ex: ['username', 'email'] will check for the username column and then email., (*5)

Select name of login field
In the same config file, you have a key loginfield. This is set to login as default. This means that the input field where you usually inputs a username or email, you use the name login, or to something you freely choose yourself., (*6)

How does it work?

If you have specified columns to log in with, if will loop through each one and try to log in. If it succeeds by one of then (first one to succeed), then it will log in with that., (*7)

There is a catch tho.. If you for an example have set the columns to allow username, phone and email, in that specific order, then you have to be alert what the username might be. Someone can have created a username as someone else email. If they by any chance have the same password, someone will have access to another account., (*8)

As a fallback if you want to use laravel's default, you can simply change the columns in the config to a null value, like this, (*9)

[
    'columns' => null,
]

The Versions

29/01 2016

dev-master

9999999-dev

Makes it possible to log in with both a username and / or email

  Sources   Download

The Requires

 

by Morten Mehus

laravel auth field multiple authorisation authenticate fields column multi columns

29/01 2016

v0.1.0

0.1.0.0

Makes it possible to log in with both a username and / or email

  Sources   Download

The Requires

 

by Morten Mehus

laravel auth field multiple authorisation authenticate fields column multi columns