Password validation rule

This commit is contained in:
PovilasKorop
2021-11-01 08:57:53 +02:00
parent 0240281ef9
commit 614234e4f0
2 changed files with 36 additions and 0 deletions
+12
View File
@@ -79,3 +79,15 @@ In file `routes/web.php` add a Middleware to that URL.
Test method: `test_password_confirmation_page()`.
---
## Task 7. Password with Letters.
By default, registration form requires password with at least 8 characters.
Add a validation rule so that password must have at least one letter, no matter uppercase or lowercase.
So password `12345678` is invalid, but password `a12345678` is valid.
Hint: you need to modify file `app/Http/Controllers/Auth/RegisteredUserController.php`, which is almost default from Laravel Breeze.
Test method: `test_password_at_least_one_uppercase_lowercase_letter()`.
+24
View File
@@ -6,6 +6,7 @@ use App\Models\User;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Auth;
use Illuminate\Validation\ValidationException;
use Tests\TestCase;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\URL;
@@ -130,4 +131,27 @@ class AuthenticationTest extends TestCase
$response->assertRedirect();
$response->assertSessionHasNoErrors();
}
public function test_password_at_least_one_uppercase_lowercase_letter()
{
$user = [
'name' => 'New name',
'email' => 'new@email.com',
];
$invalidPassword = '12345678';
$validPassword = 'a12345678';
$this->post('/register', $user + [
'password' => $invalidPassword,
'password_confirmation' => $invalidPassword
]);
$this->assertDatabaseMissing('users', $user);
$this->post('/register', $user + [
'password' => $validPassword,
'password_confirmation' => $validPassword
]);
$this->assertDatabaseHas('users', $user);
}
}