LARAVEL LARAVEL Authentication & Security 1 — Questions and Answers
Question 1: Which Laravel package provides a simple, pre-built authentication scaffolding including login, registration, and password reset?
- Laravel Breeze (Correct answer)
- Laravel Fortify
- Laravel Passport
- Laravel Sanctum
Correct answer: Laravel Breeze
Laravel Breeze is a minimal authentication starter kit that scaffolds routes, controllers, and Blade views for basic auth features.
Question 2: How do you check if a user is authenticated in a Laravel controller?
- auth()->check() (Correct answer)
- Auth::loggedIn()
- session()->authenticated()
- user()->exists()
Correct answer: auth()->check()
auth()->check() returns a boolean indicating whether the current session has an authenticated user.
Question 3: What is the purpose of Laravel Sanctum?
- To provide lightweight API token authentication and SPA authentication (Correct answer)
- To manage OAuth2 server flows for third-party apps
- To encrypt all database columns
- To rate-limit authentication attempts
Correct answer: To provide lightweight API token authentication and SPA authentication
Laravel Sanctum offers a simple token-based authentication system for SPAs, mobile apps, and simple API token issuance without full OAuth2 complexity.
Question 4: Which `auth` middleware key restricts a route to authenticated users in Laravel?
- auth (Correct answer)
- verified
- throttle
- signed
Correct answer: auth
The auth middleware redirects unauthenticated requests to the login page, ensuring only logged-in users can access the protected route.
Question 5: What does `Hash::make()` do in Laravel?
- Creates a bcrypt hash of a given string for secure password storage (Correct answer)
- Generates an MD5 checksum of a file
- Encrypts a value using the application key
- Creates a signed URL hash
Correct answer: Creates a bcrypt hash of a given string for secure password storage
Hash::make() uses bcrypt (or Argon2 depending on config) to create a one-way cryptographic hash suitable for storing passwords.
Question 6: Which method verifies a plain-text password against a stored hash in Laravel?
- Hash::check($plainText, $hashedValue) (Correct answer)
- Hash::verify($plainText, $hashedValue)
- Hash::compare($plainText, $hashedValue)
- Hash::validate($plainText, $hashedValue)
Correct answer: Hash::check($plainText, $hashedValue)
Hash::check() compares a plain-text string against a hashed value and returns true if they match, used during login validation.
Which Laravel package provides a simple, pre-built authentication scaffolding including login, registration, and password reset?