Search
 
SCRIPT & CODE EXAMPLE
 

PHP

Laravel Password Validation

'password' => 'required|
               min:6|
               regex:/^.*(?=.{3,})(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[dx])(?=.*[!$#%]).*$/|
               confirmed',
Comment

validate password laravel

        $request->validate([
            'email' =>'required|exists:users',
            'password'=>'required|password'
        ]);
Comment

validate user password laravel8

    $data = request()->validate([
        'firstname' => ['required', 'string', 'max:255'],
        'lastname' => ['required', 'string', 'max:255'],
        'username' => ['bail', 'nullable', 'string', 'max:255', 'unique:users'],
        'email' => ['bail', 'nullable', 'string', 'email:rfc,strict,dns,spoof,filter', 'max:255', 'unique:users'],
        'new_password' => ['nullable', 'string', 'min:8'],
        'confirm_new_password' => ['nullable', 'required_with:new_password', 'same:new_password'],
        'current_password' => ['required', function ($attribute, $value, $fail) {
            if (!Hash::check($value, Auth::user()->password)) {
                return $fail(__('The current password is incorrect.'));
            }
        }]
    ]);
Comment

laravel validate change password

<?php
   
namespace AppHttpControllers;
   
use IlluminateHttpRequest;
use AppRulesMatchOldPassword;
use IlluminateSupportFacadesHash;
use AppUser;
  
class ChangePasswordController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }
   
    /**
     * Show the application dashboard.
     *
     * @return IlluminateContractsSupportRenderable
     */
    public function index()
    {
        return view('changePassword');
    } 
   
    /**
     * Show the application dashboard.
     *
     * @return IlluminateContractsSupportRenderable
     */
    public function store(Request $request)
    {
        $request->validate([
            'current_password' => ['required', new MatchOldPassword],
            'new_password' => ['required'],
            'new_confirm_password' => ['same:new_password'],
        ]);
   
        User::find(auth()->user()->id)->update(['password'=> Hash::make($request->new_password)]);
   
        dd('Password change successfully.');
    }
}
Comment

password validation rules laravel

// Laravel 8+

// Require at least 8 characters...
Password::min(8)

// Require at least one letter...
Password::min(8)->letters()

// Require at least one uppercase and one lowercase letter...
Password::min(8)->mixedCase()

// Require at least one number...
Password::min(8)->numbers()

// Require at least one symbol...
Password::min(8)->symbols()
  
// Or you can chain them all
use IlluminateValidationRulesPassword;

$rules = [
    'password' => [
        'required',
        'string',
        Password::min(8)
            ->mixedCase()
            ->numbers()
            ->symbols()
            ->uncompromised(),
        'confirmed'
    ],
]
Comment

laravel password validation

use IlluminateSupportFacadesValidator;
use IlluminateValidationRulesPassword;

$validator = Validator::make($request->all(), [
    'password' => ['required', 'confirmed', Password::min(8)],
]);
Comment

laravel validate change password

<?php
  
namespace AppRules;
  
use IlluminateContractsValidationRule;
use IlluminateSupportFacadesHash;
  
class MatchOldPassword implements Rule
{
    /**
     * Determine if the validation rule passes.
     *
     * @param  string  $attribute
     * @param  mixed  $value
     * @return bool
     */
    public function passes($attribute, $value)
    {
        return Hash::check($value, auth()->user()->password);
    }
   
    /**
     * Get the validation error message.
     *
     * @return string
     */
    public function message()
    {
        return 'The :attribute is match with old password.';
    }
}
Comment

PREVIOUS NEXT
Code Example
Php :: php test page 
Php :: check variable type in php 
Php :: php required 
Php :: laravel model query limit 
Php :: php string parse with separator explode 
Php :: php move file to another directory 
Php :: get data in descending order in laravel 
Php :: regex php password 
Php :: A non well formed numeric value encountered 
Php :: how to call a helper function in blade 
Php :: how to define function in php 
Php :: download html content from url php 
Php :: php begin 
Php :: laravel map array 
Php :: current time input field in laravel form 
Php :: php link to page 
Php :: enable gd php 
Php :: foreign key laravel migration 
Php :: import facade URL laravel 
Php :: php datetime set timezone 
Php :: define constant in php 
Php :: comparing floats php 
Php :: laravel get single column value 
Php :: php get max key in associative array 
Php :: twig for loop key 
Php :: php redirect seconds 
Php :: how to get last id in database codeigniter 4 
Php :: select sum laravel 
Php :: Unable to create PsySH runtime directory. Make sure PHP is able to write to /run/user in order to continue. 
Php :: Get current taxonomy term ID of the active page 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =