mirror of
https://github.com/10h30/Test-Laravel-Auth-Basics.git
synced 2026-07-11 10:46:16 +09:00
Password validation rule
This commit is contained in:
@@ -79,3 +79,15 @@ In file `routes/web.php` add a Middleware to that URL.
|
|||||||
Test method: `test_password_confirmation_page()`.
|
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()`.
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ use App\Models\User;
|
|||||||
use App\Providers\RouteServiceProvider;
|
use App\Providers\RouteServiceProvider;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
use Illuminate\Support\Facades\Event;
|
use Illuminate\Support\Facades\Event;
|
||||||
use Illuminate\Support\Facades\URL;
|
use Illuminate\Support\Facades\URL;
|
||||||
@@ -130,4 +131,27 @@ class AuthenticationTest extends TestCase
|
|||||||
$response->assertRedirect();
|
$response->assertRedirect();
|
||||||
$response->assertSessionHasNoErrors();
|
$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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user