douyan6742 2015-07-29 19:10
浏览 381

Laravel auth无法使用正确的用户名/密码组合

For some reason, I'm unable to login with the correct username/password combination. I'm using flash messages to show when the login information is incorrect.

I've tried creating multiple accounts to make sure I wasn't actually entering the wrong login credentials, but after about an hour of fiddling it's still not working.

Any help would be greatly appreciated! Thank you!

Here's what I got.

UsersController.php (postCreate) - Function that creates my user account (working perfectly fine)

public function postCreate() {

        $rules = array(
        'username'=>'required|unique:users,username|alpha_dash|min:4',
        'password'=>'required|min:8|confirmed',
        'password_confirmation'=>'required|min:8',
        'email'=>'required|email|unique:users,email'
        );

        $input = Input::only(
            'username',
            'password',
            'password_confirmation',
            'email'
        );

        $validator = Validator::make($input, $rules);

        if($validator->fails())
        {
            return Redirect::to('register')->withErrors($validator)->withInput();
        }

        //$confirmation_code = str_random(30);

        User::create(array(
            'username'=>Input::get('username'),
            'password'=>Hash::make(Input::get('password')),
            'email'=>Input::get('email')
            //'comfirmation_code' => $confirmation_code
        ));

        // Mail::send('email.verify', function($message) {
        //  $message->to(Input::get('email'), Input::get('username'))
        //      ->subject('Verify your email address');
        // });

        // Flash::message('Thanks for signing up! Please check your email.');

        return Redirect::to('login')->with('message', 'Thanks for signing up! Please check your email.');
    }

UsersController.php (postLogin) - Function that logs me into account

public function postLogin() {
        $user = array(
            'email'=>Input::get('email'),
            'password'=>Input::get('password')
        );

        if (Auth::attempt($user)){
            return Redirect::intended('account')->with('message', 'Welcome back!');
        } else {
            return Redirect::to('login')
                ->with('message', 'Your username/password was incorrect')
                ->withInput();

        }
    }

Routes.php

Route::get('login', array('as'=>'login', 'uses'=>'UsersController@getLogin'));
Route::post('login', array('before'=>'csrf', 'uses'=>'UsersController@postLogin'));

login.blade.php - My login Page

@if($errors->has())
        <p>The following errors have occured:</p>

        <ul id="form-errors">
            {{ $errors->first('username', '<li>:message</li>') }}
            {{ $errors->first('password', '<li>:message</li>') }}
        </ul>   
    @endif

    @if (Session::has('message'))
        <p>{{ Session::get('message') }}</p>
    @endif

    {{ Form::open(array('action'=>'login')) }}

    <p>
        {{ Form::label('username', 'Username') }}<br />
        {{ Form::text('username', Input::old('username')) }}
    </p>

    <p>
        {{ Form::label('password', 'Password') }}<br />
        {{ Form::password('password') }}
    </p>

    <p>
        {{ Form::submit('Login') }}
    </p>

    {{ Form::close() }}
  • 写回答

2条回答 默认 最新

  • duancuisan2503 2015-07-29 19:17
    关注

    In your

    UsersController.php (postCreate) - : You are able to create using password with Hash 'password'=>Hash::make(Input::get('password')),

    AND

    UsersController.php (postLogin) : You are trying to login using 'password'=>Input::get('password') So this should replace with

    'password'=>Hash::make(Input::get('password'))

    Also hashed passwords required 64 charactters for database field. so check that too.

    评论

报告相同问题?

悬赏问题

  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计