Я собираюсь предсказать это, сказав, УБЕДИТЕСЬ, ЧТО ВЫ ЗНАЕТЕ, ЧТО ВЫ ДЕЛАЕТЕ. Это чрезвычайно опасно. Вы ни при каких обстоятельствах не должны хранить пароли без их хеширования.
В вашем LoginController.php
переопределите функцию входа в систему с AuthenticatesUsers.php
. Скопируйте то, что уже есть в AuthenticatesUsers.php
, потому что нам действительно нужно беспокоиться о вызове функции attempt()
.
Я собираюсь предположить, что вы не хэшируете сохраненные пароли, и в этом случае вам нужно только чтобы проверить, совпадает ли предоставленный пароль с паролем, который вы сохранили.
Сначала вы захотите получить пользователя с введенным им именем пользователя, поэтому $user = User::whereUsername($request->input('username'))->first();
затем подтвердите свой сохраненный пароль по вводу, поэтому $user->password === $request->input('password');
. Затем вам нужно использовать фасад Auth
для аутентификации пользователя, чтобы остальная черта AuthenticatesUsers.php
могла работать эффективно.
Будут некоторые изменения в зависимости от того, как вы настроили Ваша пользовательская модель, но приведенная ниже должна дать вам суть вещей.
Все это должно выглядеть так:
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\User;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = '/home';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
public function login(Request $request)
{
$this->validateLogin($request);
// If the class is using the ThrottlesLogins trait, we can automatically throttle
// the login attempts for this application. We'll key this by the username and
// the IP address of the client making these requests into this application.
if (method_exists($this, 'hasTooManyLoginAttempts') &&
$this->hasTooManyLoginAttempts($request)) {
$this->fireLockoutEvent($request);
return $this->sendLockoutResponse($request);
}
$user = User::whereUsername($request->input('username'))
->wherePassword($request->input('password'))
->first();
if ($user !== null) {
Auth::login($user);
return $this->sendLoginResponse($request);
}
// If the login attempt was unsuccessful we will increment the number of attempts
// to login and redirect the user back to the login form. Of course, when this
// user surpasses their maximum number of attempts they will get locked out.
$this->incrementLoginAttempts($request);
return $this->sendFailedLoginResponse($request);
}
}