как убрать ха sh из laravel 5.8 | я хочу удалить laravel ха sh форму из логина и регистрации - PullRequest
0 голосов
/ 17 января 2020

Я хочу удалить laravel га sh формат из реестра и войти в систему. уже пробую другим способом, но безуспешно. так что любое тело поможет мне.

<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

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 = '/admin-panel';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        return redirect()->to('admin-login');
        //$this->middleware('guest')->except('logout');
    }
}

Ответы [ 2 ]

1 голос
/ 17 января 2020

В App \ Http \ Controllers \ Auth \ Registercontroller. php

Прокрутите вниз и в функции создания удалите 'password' => Hash::make($data['password']), до 'password' => $data['password'],

Для копии входа вставьте эту в LoginController:

protected function attemptLogin(Request $request)
{
    $user = User::where('email', $request->username)
        ->where('password', $request->password)
        ->first();

    if(!isset($user)){
        return false;
    }

    Auth::login($user);

    return true;
}
0 голосов
/ 17 января 2020

Я собираюсь предсказать это, сказав, УБЕДИТЕСЬ, ЧТО ВЫ ЗНАЕТЕ, ЧТО ВЫ ДЕЛАЕТЕ. Это чрезвычайно опасно. Вы ни при каких обстоятельствах не должны хранить пароли без их хеширования.


В вашем 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);
    }
}

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...