Skip to main content

Password Validation Rule Object in laravel8 by laravelnote

 Originally released in Laravel 5.5, custom validation rule objects offer a fluent alternative to string-based rules. In its simplest form, the Password rule object replaces string-based validation rules:

<?php

// String-based
$request->validate([
    'password' => 'required|string|confirmed|min:8',
]);

// Using the Password rule object
$request->validate([
    'password' => ['required', 'confirmed', Password::min(8)],
]);

In addition to replacing string rules with a fluent password rule object, the custom password rule object includes built-in methods for ensuring strong passwords:

<?php

$request->validate([
    'password' => [
        'required',
        'confirmed',
        Password::min(8)
            ->mixedCase()
            ->letters()
            ->numbers()
            ->symbols()
            ->uncompromised(),
    ],
]);

Never write custom regex logic for typical scenarios such as requiring mixed-case, letters, symbols, etc. The cherry on the top is the uncompromised() method which checks the password against a verification API to see if the password appears in data leaks. The release will ship with a NotPwnedVerifier implementation which uses the Have I Been Pwned API.

In addition to this excellent new custom validation object, Pull Request #36960 contains some good examples of using Laravel to test API calls and validation.

Depending on when Laravel 8.39 gets tagged, this feature might be available at the time of publication Tuesday, April 27th. Keep your eyes peeled for the release of this awesome feature!

Laravel laravel8 by laravelnote.



Popular posts from this blog

Laravel8 in Serializes Models trait | laravelnote

This article was originally posted, with additional formatting, on my personal blog at laravel serializes model Background  When dispatching an object onto the queue, behind the scenes Laravel is recursively serializing the object and all of its properties into a string representation that is then written to the queue. There it awaits a queue worker to retrieve it from the queue and unserialize it back into a PHP object (Phew!). Problem When complicated objects are serialized, their string representations can be atrociously long, taking up unnecessary resources both on the queue and application servers. Solution Because of this, Laravel offers a trait called SerializesModels which, when added to an object, finds any properties of type Model or Eloquent\Collection during serialization and replaces them with a plain-old-PHP-object (POPO) known as a ModelIdentifier. These identifier objects represent the original properties Model type and ID, or IDs in the case of an Eloquent\Collecti...

Octane Support in Laravel forge 2021 5 may

 Back in March, Taylor announced the new Laravel Octane project at Laracon Online. Since then, we've been busy working on bug fixes and enhancements to Octane, as well as adding support to Laravel Forge. Today we're pleased to announce that Octane support is available in Forge. We've written the guide below to help you get started. Please keep in mind that Octane is still in beta and should not be used in production. Prerequisites Your project must require "laravel/octane": "^0.3.2" or above. Your server must have PHP 8.0 installed. You should then follow the Octane installation instructions listed in the Octane repository. Creating an Octane Site Octane can be enabled by selecting the Laravel Octane (Beta) project type option and PHP 8.0 as the PHP version that should be used to serve your site: Laravel Octane Project Type Laravel Octane Project Type Once the project type has been selected, Forge will ask for the port that Octane should listen on. Unlik...

Create Your Next Project's Readme in Laravel8 | laravelnote

  The readme.so editor gives you visual cues, starter section templates and includes many standard readme sections you're likely to use. It also has a nice preview to help guide you along the way. Never forget a section for your readme again! Select sections to add to your readme, edit the contents, and drag to rearrange. See a live-updating rendered preview of your markdown, then download your README.md file! Here's an example of starting an API section, which provides helpful formatting. You might need to specify API params: The editor includes both light and dark editor support, and you can download or copy/paste the raw markdown of your readme into version control once you're done. You can learn more about this project and start using it on  readme.so . Also, be sure to check out  readme.so on Product Hunt  and upvote it if you find it useful!