Laravel User Authentication with Username instead of Email

The Laravel standard authentication method is to enter email-address and password to login after the authentication is added with php artisan make:auth.
If you are working on an application for a company that is only used by employees, they have their usernames and passwords, so it doesn’t make sense to sign in with the email-address.

At the registration process, which will be done in this case by an administrator, a username is already requested. I saw some videos for this type of registration with an extra username database field for registration. I’m the existing one.

Laravel 5.4 needs php7. Not all servers of the world run still on php7. So I show how the authentication with the username works on Laravel 5.4 and 5.2.45 which runs under php5.

Laravel 5.4
Edit app/Http/Controllers/Auth/LoginController.php

(click to enlarge)


protected $username = 'name';
 public function username()
 return 'name';

like it is shown i the picture.
Laravel has still a function for authentication with the username. I this case the variable $username is filled with our database field „name“ which is the name of the user which was used at registration.

Edit app/Http/Controllers/Auth/RegisterController.php

(click to enlarge)

Add the „unique“ attribute to „name“ in the Validator.

Edit resources/views/auth/login.blade.php

(click to enlarge)

Change all the the „email“ to „name“. If you use find / replace take care of the type-attribute at input. It should be „text“ and not „name“. 😉

Laravel 5.2.45

Here are other controllers for authentication.

Edit app/Http/Controllers/Auth/AuthController.php

(click to enlarge)

Add only

protected $username = 'name';

like it is shown in the picture and add the „unique“ attribute to „name“ in the Validator.
Than change the view like in Laravel 5.4.

Screen tearing on Linux on Thinkpad X201 with Ultrabase Dock on external LCD display

I have had the problem, that „waves“ were moving from the bottom of the monitor to the top.
It was not important which linux distribution I used. It was the same on every distribution. But most worst it was on XFCE environments. I tried to fix it with driver options and other compositors like compton, but nothing really helps.
For another reason I unplugged one time all USB devices from the dock. And the screen tearing was gone. I was surprised.
I found that the tearing comes from the power management. It tries to turn USB devices of and turn them directly on again. That results the tearing on the screen.
There is an advanced power management system called tlp that is available for every distribution.
Install tlp and set USB_AUTOSUSPEND = 0 in /etc/default/tlp . After that restart the computer or restart the service tlp and the „waves“ are history.
I tested this with Ubuntu MATE, Xubuntu, Ubuntu Gnome, Opensuse XFCE / Gnome, Debian XFCE / MATE / Gnome, Fedora Gnome 24/25, Manjaro XFCE and Linux Mint 18 MATE / Cinnamon.
Perhaps this will work with other machines with an intel i915 graphic chip.


Install LAMPP Stack on Ubuntu MATE Xenial Xerus 16.04

I used the Beta 2 Version for this tutorial and have rebuild my whole Ubuntu Mate 14.04 environment on 16.04 Beta 2 from the computer I use every day for business and it works flawless. I like Ubuntu MATE because it is stable. This Beta 2 is more stable than other distros after release date. And I can do all my stuff with this distro like programming in python, php, lazarus, java, making printing templates for the printery with gimp, inkscape, scribus in pdf/x format and icc cmyk profiles, making videos with openshot and all the other things with libreoffiice. MATE is the best balanced DE between resource saving and usability.
For wordpress and web development I need a local web server every day. Php 7 is the most recent version of php, but most web servers use php5 until now.

WordPress works fine with php7 but many plugins have problems. And without plugins wordpress is useless.
So I install php5, because it makes no sense to develop things, that can’t be used in the real live.

Some things are different from the installation on 14.04.
I installed apache2, mariadb, php5 and myphpadmin. lampp

Update 5/29/2016
PHP5 is no longer available in Ubuntu repositories.
You can only install PHP7 from there.

But there is a ppa for PHP5.6.
So the installation process changed.
Here is how to install apache2, mariadb, php5.6 and myphpadmin using the ppa:

First open a terminal and install the packages:

sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt-get install apache2
sudo apt-get install mariadb-server

Mariadb has no root password by default. You should set a password else you will get in trouble with phpmyadmin when logging in from the browser. Change new_password to your new password. To set the root password follow these steps in a terminal:

sudo mysql -uroot -p
use mysql
update user set password=PASSWORD("new_password") where User='root';
update user set plugin='' where User='root';
flush privileges;

Restart mariadb.

systemctl restart mysql

Install PHP5.6 and phpmyadmin

sudo apt-get install php7.0 php5.6 php5.6-mysql php-gettext php5.6-mbstring 
sudo apt-get install php-xdebug libapache2-mod-php5.6 libapache2-mod-php7.0
sudo apt-get install php php-mysql php5.6-gd phpmyadmin libapache2-mod-php 
sudo apt-get install php5.6-curl php5.6-zip php5.6-xml php5.6-soap 
sudo apt-get install php-mbstring php-gettext php5.6-mcrypt 

Phpmyadmin asks for the password of mariadb while installation. 
If you get an error 1045 while installation, hit „ignore“.
When you start phpmyadmin the first time, a message comes up to install

To switch between PHP5 and PHP7 use a2enmod

sudo a2dismod php5
sudo a2enmod php7.0

The version numbers can differ with the years. You will find all avalible modules at

If you want to use wordpress with pretty permalinks (e.g you have to enable mod_rewrite.

sudo a2enmod rewrite
systemctl restart apache2

Now tell apache to use pretty permalinks and edit the apache config file.

sudo pluma /etc/apache2/apache2.conf

Search for : <Directory /var/www/> and replace

AllowOverride None


AllowOverride All

in this section, save the file and restart apache.

systemctl restart apache2

Now the basic configuration is done and you can use the LAMPP stack as it is.
The root directory is /var/www by default. I don’t like that, because there is always trouble with the permissions. I put the web server root directory in my home directory.
That means no trouble with permissions and it is easy to backup.

Create a new directory as server root in your home directory.

mkdir /home/username/html

Edit the default virtualhost file:

sudo pluma /etc/apache2/sites-available/000-default.conf

change DocumentRoot from /var/www to the path of your new server root
e.g. /home/username/html
Take care: There is NO slash behind the last directory.

Edit apache2.conf:

sudo pluma /etc/apache2/apache2.conf

Search for : <Directory /var/www/> and replace /var/www with your new server root
e.g. /home/username/html/
Take care: There IS a slash behind the last directory.

On my own laptop I don’t deal with permissions so I changed them for the html directory to 777. Never do this on a production machine.

sudo chmod -R 777 /home/username/html

That’s it.