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

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 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化