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 VB.NET2022如何生成发布成exe文件
  • ¥30 matlab appdesigner私有函数嵌套整合
  • ¥15 给我一个openharmony跑通webrtc实现视频会议的简单demo项目,sdk为12
  • ¥15 vb6.0使用jmail接收smtp邮件并另存附件到D盘
  • ¥30 vb net 使用 sendMessage 如何输入鼠标坐标
  • ¥15 关于freesurfer使用freeview可视化的问题
  • ¥100 谁能在荣耀自带系统MagicOS版本下,隐藏手机桌面图标?
  • ¥15 求SC-LIWC词典!
  • ¥20 有关esp8266连接阿里云
  • ¥15 C# 调用Bartender打印机打印