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.

J2EE with Netbeans and Tomcat with Ubuntu Mate

You should have installed a recent java jdk. If you want also use java FX install the Oracle jdk. Open jdk has some trouble with java FX cause licences.
J2EE may not be downloaded from Oracle separately.
Install Netbeans from the Ubuntu repository and download tomcat .gz file from
Netbeans will be version 8.1 and I use tomcat 8.5.15. My OS is Ubuntu Mate 17.04.
Extract the apache-tomcat-8.5.15.tar.gz to your home-folder or where ever you want.
Start Netbeans and select from the Tools menu Plugins.
Add Java EE Base and EjB and EAR plugins.

(click to enlarge)

Without the EjB and EAR plugin an „javaee-endorsed-api-7.0.jar missing error“ will raise, when you start a new project.

Go to the Tool menu and choose Servers.
Click on Add Server .. down left in the window and choose Apache Tomcat or TomEE.
The server location is the root directory where tomcat was extracted to, i.e. the tomcat folder in your home folder.
Enter a username and a password and leave the option „Create user …“ checked.

There is also a well known bug in the tomcat configuration you have to fix.
Open the server.xml in <tomcat-folder>/bin set the connector tag as comment and define the connector like this:


(click to enlarge)

That’s it.
Now you can start a new project and test the installation. When click on the green arrow for „run project“ the code will be deployed, tomcat is starting and a new browser-window or tab opens with the result of your code.
This setup is so much easier than with MS Windows. And except download times you will be back at work in less than 15 minutes.

(click to enlarge)


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.