I’ve trying to create a Password Strength Meter With Regex I made some tricks but it look like not working as I expected ?
I’m using this package inside livewire component : https://github.com/bjeavons/zxcvbn-php
App\Http\Livewire\ExampleForm
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use ZxcvbnPhp\Zxcvbn;
class ExampleForm extends Component
{
public $name = '';
public $email = '';
public $password = '';
public $passwordStrength = 0;
protected $rules = [
'name' => 'required|min:6',
'email' => 'required|email',
'password' => 'required',
];
public function updated($propertyName)
{
$this->validateOnly($propertyName);
}
public function updatedPassword($password)
{
$zxcvbn = app(ZxcvbnPhp\Zxcvbn::class)->passwordStrength('password', $value);
$this->passwordStrength = $zxcvbn['score'];
}
public function saveUser()
{
$validatedData = $this->validate();
User::create($validatedData);
}
public function render()
{
return view('livewire.example-form');
}
}
example-form
<form wire:submit.prevent="saveUser">
<input type="text" wire:model="name">
@error('name') <span class="error">{{ $message }}</span> @enderror
<input type="text" wire:model="email">
@error('email') <span class="error">{{ $message }}</span> @enderror
<input type="password" wire:model="password">
<div class="progress">
<div class="progress-bar" role="progressbar" style="width: {{ $passwordStrength }}%" aria-
valuenow="{{ $passwordStrength}}" aria-valuemin="0" aria-valuemax="100"></div>
</div>
@error('password') <span class="error">{{ $message }}</span> @enderror
<button type="submit">Submit</button>
</form>