如何摆脱laravel中的bcrypt

时间:2017-07-24 13:10:35

标签: php laravel

我想摆脱bcrypt的原因(目前,在开发过程中)是因为我正在创建一个管理Android应用程序并且我将它连接到数据库。我一直有问题当我从应用程序创建用户时,他们无法登录到网站.bcrypt附带了Auth安装。 [![在此处输入图像说明] [1]] [1]

我已经发现导致此问题的已发布是bcrypt。我似乎无法找到一种方法来删除。

我想删除要求用户密码加密的网站

我在RegisterController 'password' => bcrypt($data['password'])尝试了bcrypt但是没有用

<?php

namespace App\Http\Controllers\Auth;

use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;

class RegisterController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Register Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles the registration of new users as well as their
    | validation and creation. By default this controller uses a trait to
    | provide this functionality without requiring any additional code.
    |
    */

    use RegistersUsers;

    /**
     * Where to redirect users after registration.
     *
     * @var string
     */
    protected $redirectTo = '/home';

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

    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
        return Validator::make($data, [
            'name' => 'required|string|max:255',
            'email' => 'required|string|email|max:255|unique:users',
            'password' => 'required|string|min:6|confirmed',
        ]);
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return User
     */
    protected function create(array $data)
    {
        return User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
        ]);
    }
}

这个LoginController.php

<?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 = '/home';

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

这是我的login.blade.php

@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row">
        <div class="col-md-8 col-md-offset-2">
            <div class="panel panel-default">
                <div class="panel-heading">Login</div>
                <div class="panel-body">
                    <form class="form-horizontal" role="form" method="POST" action="{{ route('login') }}">
                        {{ csrf_field() }}

                        <div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
                            <label for="email" class="col-md-4 control-label">E-Mail Address</label>

                            <div class="col-md-6">
                                <input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}" required autofocus>

                                @if ($errors->has('email'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('email') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
                            <label for="password" class="col-md-4 control-label">Password</label>

                            <div class="col-md-6">
                                <input id="password" type="password" class="form-control" name="password" required>

                                @if ($errors->has('password'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('password') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-md-6 col-md-offset-4">
                                <div class="checkbox">
                                    <label>
                                        <input type="checkbox" name="remember" {{ old('remember') ? 'checked' : '' }}> Remember Me
                                    </label>
                                </div>
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-md-8 col-md-offset-4">
                                <button type="submit" class="btn btn-primary">
                                    Login
                                </button>

                                <a class="btn btn-link" href="{{ route('password.request') }}">
                                    Forgot Your Password?
                                </a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

Web.php

    <?php
    //use Illuminate\Http\Request;
    /*
    |--------------------------------------------------------------------------
    | Web Routes
    |--------------------------------------------------------------------------
    |
    | Here is where you can register web routes for your application. These
    | routes are loaded by the RouteServiceProvider within a group which
    | contains the "web" middleware group. Now create something great!
    |
    */

    Route::get('/', function () {
        return view('welcome');
    });

    Route::get('/test', function () {
        return Auth::user()->test();
    });

    Auth::routes();


    Route::any('/home', 'HomeController@index')->name('home');

    Route::group(['as' => 'user.'], function () {


        Route::get('/front', function () {
            return view('front');
        });
        Route::get('/settings', ['as' => 'settings', 'uses' => 'ProfileController@viewSettings']);
        Route::post('/settings', ['as' => 'settings', 'uses' => 'ProfileController@saveSettings']);
        Route::any('/profile/{userId}', ['as' => 'profile', 'uses' => 'ProfileController@viewProfile']);
        Route::get('/search/{query?}', ['as' => 'search', 'uses' => 'SearchController@search']);

        Route::get('users', function () {
            return User::find(1)->toJson();
        });

        Route::get('/chat', function () {
            return view('chat');
        });

        Route::get('/calendar', function () {
            return view('calendar');
        });

        Route::resource('events', 'EventsController', ['only' => ['index', 'store', 'update', 'destroy']]);

        //Friends route
        Route::post('/friends/request', ['as' => 'friends', 'uses' => 'FriendsController@sendRequest']);
        Route::get('/friends/viewReq', ['as' => 'friends', 'uses' => 'FriendsController@viewFriendReq']);
        Route::post('/friends/reqAction', ['as' => 'friends', 'uses' => 'FriendsController@requestAction']);


        Route::get('/status-delete/{status_id}',['uses' => 'HomeController@getDeleteStatus', 'as'=> 'status.delete',
            'middleware' =>'auth'
        ]);

        Route::get('/edit/{status_id}', 'HomeController@edit');


    });

  [1]: https://i.stack.imgur.com/BFMap.jpg

1 个答案:

答案 0 :(得分:1)

您可以通过调用make上的Hash facade方法来哈希密码。在RegisterController只需将密码加密为

'password' => Hash:make($data['password'])

但要确保,您必须包含此内容才能使用Hash Facade

use Illuminate\Support\Facades\Hash;

之后,您可以使用check方法,该方法允许您验证给定的纯文本字符串是否与给定的哈希值相对应

if (Hash::check($data['password'], Hash::make($data['password']))) {
    // The passwords match...
}