From 614234e4f0e9e7a597060b5c0e000d733d734fad Mon Sep 17 00:00:00 2001 From: PovilasKorop Date: Mon, 1 Nov 2021 08:57:53 +0200 Subject: [PATCH] Password validation rule --- README.md | 12 ++++++++++++ tests/Feature/AuthenticationTest.php | 24 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/README.md b/README.md index 8341668..5fbc179 100644 --- a/README.md +++ b/README.md @@ -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()`. + diff --git a/tests/Feature/AuthenticationTest.php b/tests/Feature/AuthenticationTest.php index 1b5308f..e9a81ad 100644 --- a/tests/Feature/AuthenticationTest.php +++ b/tests/Feature/AuthenticationTest.php @@ -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); + } }