douyan6958 2014-04-09 02:25
浏览 149
已采纳

Laravel身份验证因Auth :: attempt而失败

I am trying out the Jeffrey Way Authentication Essentials Tutorial on Laravel 4, but I am getting not the same results. (https://www.youtube.com/watch?v=msEwmVZ4wp4)

When I check for dd($attempt), I always get false, even if I logged in with the right credentials.

Please someone tell me, where I am going wrong. I already google a lot, and some people claim, that the password needs to be hashed, and I hash it, before putting it into the database, but there must still be an error somewhere else.

Here is my code: http://help.laravel.io/faff81e66d3672cb96d5ae2f8d0cccbf2e7f9052

Also here the most important pieces of code:

My View with the form: create.blade.php

Login

{{ Form::open(array('route' => 'sessions.store')) }}

    <ul>
        <li>
            {{ Form::label('email', 'Email:')}}
            {{ Form::text('email')}}
        </li>
        <li>
            {{ Form::label('password', 'Password:')}}
            {{ Form::password('password')}}
        </li>
        <li>
            {{ Form::submit() }}
        </li>
    </ul>

{{ Form::close() }}

And my SessionsController.php

public function create()
{
    //
    $users = User::all();

    return View::make('sessions.create')
        ->with('users', $users);
}

/**
 * Store a newly created resource in storage.
 *
 * @return Response
 */
public function store()
{
    // validate

    $input = Input::all();

    $attempt = Auth::attempt([
        'email' => $input['email'],
        'password' => $input['password']
    ]);

    dd($attempt);

    // if($attempt) {
    //  return Redirect::intended('/');
    // } else {
    //  return 'whatever bro';
    // };

    // dd('problem');
}

Here is a screenshot of my database: http://i.imgur.com/sTGQu39.jpg

I expect the boolean of dd($attempt) to be correct, if I type in the correct login credentials, but it always shows as false.

Please can someone correct my code :)

Kind regards,

George

  • 写回答

2条回答 默认 最新

  • dpnv33177 2014-04-09 12:13
    关注

    From the screenshot of your database I can see that you are not hashing password before storing it in the database. The Auth::attempt function consider that your password is hashed so it apply Hash::make to the given password and then compare it with the one stored in the database.

    To make your code work, when registering a user you should use the Hash::make function before storing the password:

     $password = Hash::make($input['password']);
     $user->password = $password;
     $user->save(); 
    

    Take a look on the documentation http://laravel.com/docs/security

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测