Laravel – User Prevent Common Passwords using laravel-password package

Laravel – User Prevent Common Passwords using laravel-password package

In this post we will give you information about Laravel – User Prevent Common Passwords using laravel-password package. Hear we will give you detail about Laravel – User Prevent Common Passwords using laravel-password packageAnd how to use it also give you demo for it if it is necessary.

Today, i am going to share with you how to ignore common password to enter by user using “unicodeveloper/laravel-password” package. Using “unicodeveloper/laravel-password” package, we can simply use “dumbpwd” validation rule.

As we know, security is a key of website or software, If you are creating new account and you create very familiar or regular password like “123456”, “123123”, “abcd” etc. So this type of ordinary password can know or gases your password and login in to your account. So we have to use something like package or plugin for prevent this type of common password enter to user.

In this example, we are going to learn how we can prevent common password using laravel custom validation rule. laravel framework not provide by default any validation for this, so we will use “unicodeveloper/laravel-password” package that will help us.

So, let’s follow bellow few step to done this example. As you see bellow preview of error message, after done this example you can see on your project too.

Preview:

Step 1 : Install Laravel Application

This tutorial is from scratch, So we require to get fresh Laravel 5.4 application using bellow command, So open your terminal OR command prompt and run bellow command:

composer create-project --prefer-dist laravel/laravel blog

Step 2 : Make Auth

If you are doing from scratch, then you have to make sure database configuration on .env file and run migration. After that we will make auth to create login and register page. So let’s run bellow command:

php artisan make:auth

Also see:Laravel Generate Sitemap using roumen/sitemap package Example

Step 3: Install Package

In this step we have to unicodeveloper/laravel-password package for access custom validation rule method so one your cmd or terminal and fire bellow command:

composer require unicodeveloper/laravel-password

After successfully install package, open config/app.php file and add service provider and alias.

config/app.php

'providers' => [

....

UnicodeveloperDumbPasswordDumbPasswordServiceProvider::class

],

.....

Step 4: Add Validation Message

After install package successfully, we have to add custom message for package validation. So let’s add as like bellow file:


resources/lang/en/validation.php

<?php


return [


/*

|--------------------------------------------------------------------------

| Validation Language Lines

|--------------------------------------------------------------------------

|

| The following language lines contain the default error messages used by

| the validator class. Some of these rules have multiple versions such

| as the size rules. Feel free to tweak each of these messages here.

|

*/


'dumbpwd' => 'You are using a dumb password abeg',

....

Step 5: Use Validation Rule

Now, we are ready to use “dumbpwd” validation rule on register page, so let’s use like as bellow file:

app/Http/Controllers/Auth/RegisterController.php

<?php


namespace AppHttpControllersAuth;


use AppUser;

use AppHttpControllersController;

use IlluminateSupportFacadesValidator;

use IlluminateFoundationAuthRegistersUsers;


class RegisterController extends Controller

{

/*

|--------------------------------------------------------------------------

| Register Controller

|--------------------------------------------------------------------------

|

| This controller handles the registration of new users as well as their

| validation and creation. By default this controller uses a trait to

| provide this functionality without requiring any additional code.

|

*/


use RegistersUsers;


/**

* Where to redirect users after registration.

*

* @var string

*/

protected $redirectTo = '/home';


/**

* Create a new controller instance.

*

* @return void

*/

public function __construct()

{

$this->middleware('guest');

}


/**

* Get a validator for an incoming registration request.

*

* @param array $data

* @return IlluminateContractsValidationValidator

*/

protected function validator(array $data)

{

return Validator::make($data, [

'name' => 'required|max:255',

'email' => 'required|email|max:255|unique:users',

'password' => 'required|min:6|dumbpwd|confirmed',

]);

}


/**

* Create a new user instance after a valid registration.

*

* @param array $data

* @return User

*/

protected function create(array $data)

{

return User::create([

'name' => $data['name'],

'email' => $data['email'],

'password' => bcrypt($data['password']),

]);

}

}

Now we are ready to run our example so run bellow command for quick run:

php artisan serve

Now you can open bellow URL on your browser:

Also see:Laravel – Twitter API using thujohn/twitter tutorial

http://localhost:8000/

You can get more information from here about this package : laravel-password

I hope it can help you….

Hope this code and post will helped you for implement Laravel – User Prevent Common Passwords using laravel-password package. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

7  +  1  =  

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US