Hello Folks,
Today i will be showing you how to implement PHP login with QRcode in a website.
We will be using PHP laravel framework so a basic understanding of Laravel and composer is needed.
1. Install composer unto your computer.
2. Goto https://github.com/laravel/laravel and download the laravel framework.
3. Unzip it into a folder in your www folder.
4. Open your console and cd into the laravel folder.
5. Run ‘composer install’ and wait for it to install the laravel framework.
6. Run ‘php artisan key:generate’ to generate your app private key.
7. Create a new mysql database with the name ‘qrlogin’ or any name of your choose.
8. From your file explorer goto the app/config folder and open the database.php file.
9. On line 55-64 configure the mysql connection strings to suit your mysql database parameters.
10. From your console run ‘php artisan migrate:install’ and then ‘php artisan migrate:make create_users_table’.
11. Goto app/database/migrations and open this new migration.
12. Copy and paste the following:
increments('id'); $table->string('email'); $table->string('password'); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::drop('users'); } }
13. Open app/routes.php file and copy and paste the following:
first(); if( $records ) { echo '
‘; //display qrcode QRcode::png($records->qrdata, $filename, $errorCorrectionLevel, $matrixPointSize, 2); echo ‘‘; die(); } //Add if check fails $_userToDB = new User; $_userToDB->email = $email; $_userToDB->password = $password; $_userToDB->qrdata = $qrdata; if( $_userToDB->save() ) { echo ‘
‘; //display qrcode QRcode::png($_userToDB->qrdata, $filename, $errorCorrectionLevel, $matrixPointSize, 2); echo ‘‘; die(); }else { echo ‘
‘; die(); } }else { echo ‘
‘; die(); } }); Route::post(‘/login’, function() { $qrdata = Input::get(‘qrdata’); if(!empty( $qrdata )) { $records = User::where(‘qrdata’, ‘=’, $qrdata)->first(); if( $records ) { echo ”
Welcome “. $records->email .”
You are in the users area.”; echo “.loginform { display: none; }”; }else { echo ‘
‘; die(); } }else { echo ‘
‘; die(); } });
14. Goto https://github.com/Kephson/html5qrcodereader and download the repo then unzip it into your app/public folder.
15. Goto the app/views folder and create two files namely:
‘master.blade.php’
and
‘index.blade.php’
16. Copy and paste the following into ‘master.blade.php’
@yield('title') @yield('section')
and the following in ‘login.blade.php’
@extends('master') @section('title') $(document).ready(function() { $("#signup").click(function (e) { e.preventDefault(); $('#signup').disabled; $('.loader').html('Please Wait...'); if($('#email').val() === '' || $('#password').val() === '') { //send error $('.error').html('
‘); $(‘.loader’).html(”); return false; } var email = $(‘#email’).val(); var password = $(‘#password’).val(); jQuery.ajax({ type: “POST”, url: “/signup”, //Where form data is sent on submission dataType:”HTML”, // Data type, HTML, json etc. data:{ email: email, password: password }, //Form variables success:function(data){ $(‘#regform’).html(”); $(‘.error’).html(data); }, error:function (xhr, ajaxOptions, thrownError){ $(‘.error’).html(‘
‘); $(‘.loader’).html(”); return false; } }); }); }); Simple PHP login using Qr-Code and Laravel @stop @section(‘section’)
Simple PHP login using Qr-Code and Laravel
This is a simple implimentation of PHP login system using qrcode and laravel php framework. To register an account please click on the botton below.
SignUp
Login
Please use your qrcode to login below.
@stop
17. Goto ‘C:wamp binapacheapache2.4.9conf’ and open the ‘httpd.conf’ file.
18. At the end of the file copy and paste the content below:
NameVirtualHost 127.0.0.1 <VirtualHost 127.0.0.1> ServerName local.qrlogin.com DocumentRoot "C:/wamp/www/qrlogin-laravel/public" <Directory C:/wamp/www/qrlogin-laravel/public> Order Allow,Deny Allow from all </Directory> </VirtualHost>
19. Goto ‘C:WindowsSystem32Driversetc’ and open the ‘hosts’ file.
20. Copy and paste the content below
127.0.0.1 local.qrlogin.com
21. Goto ‘/path/to/qrlogin-laravel/app/config/’ and open ‘app.php’.
on line 29 edit the url to http://local.qrlogin.com
22. Restart Apache and goto http://local.qrlogin.com on your browser.
# Method 2. Using localhost if you have difficulty in 17-22
Navigate your browser to ‘http://localhost/qrlogin-laravel/public’.
You can download the project at https://github.com/aminubakori/qrlogin-laravel. Follow the instructions on the repo.
Happy Hacking 🙂
Happy Scaning :))