2

こんにちは、私はlaravelが初めてで、ログインフォームの機能をコーディングしようとしています。コードは次のとおりです。

これは私が新しいユーザーを作成する方法です(うまくいきます)

public function action_newuser()
{

    $email = Input::get('email');
    $password = Input::get('password');
    $new_user = Input::get('new_user', 'off');
    $first_name= Input::get('firstname');
    $last_name= Input::get('last_name');
    $username= Input::get('username');

    $user = new User();
    $user->email = $email;
    $user->password = Hash::make($password);
    $user->first_name =$first_name;
    $user->last_name= $last_name;
    $user->username= $username;
    try{

        $user->save();
    }
    catch(Exception $e) {
        echo "Failed to create new user!";
    }

これは私のログイン機能です:

public function action_login()
{   

    $password = Input::get('password');    
    $username= Input::get('username');
    $remember= Input::get('remember', 'off');
    if($remember =='off')   $remember=FALSE;
    if($remember =='on') $remember=TRUE;
    $credentials = array(
            'username' => $username,
            'password' => $password,
            'remember' => $remember   
        );
     if( Auth::attempt($credentials)) 
        {
            return Redirect::to('dashboard/index');
        } 
        else 
        {
            #I put this line to check are the values passed from my form are correct.
            echo $password.'  ' .$username.' '. $remember;

        }


}   

ログイン フォームを送信すると、常に空白のページに $password、$username、および $remember の値が表示されます。これは、Auth::attempt() がうまく機能していないことを意味します。

何が問題になる可能性がありますか?

4

3 に答える 3

4

私をだます!何度も確認しましたが'username' => 'email', 、認証設定ファイルにその行が見当たりませんでした。

'username' => 'username',ログインにユーザー名を使用するので、そうする必要があります。

于 2012-11-05T12:09:13.077 に答える
3

データベースのパスワード フィールドが 60 文字であることを確認してください。

于 2012-11-05T11:32:28.900 に答える
1

Auth::attempt() のログイン失敗に直面しているすべての laravel 4 開発者に、有効なクレジットを使用してください!

解決:

  • app/config/app.php でタイプを変更: 'cipher' => MCRYPT_RIJNDAEL_128 を 'cipher' => MCRYPT_RIJNDAEL_256 に変更し、すべてのパスワードを再ハッシュします。
  • モデル内でメソッドを追加:

     public function setPasswordAttribute($pass) {
    
         $this->attributes['password'] = Hash::make($pass);
     }
    
  • ユーザーコントローラーで:

    //ユーザーの作成または登録

       public function postCreate() {
    
        $input = Input::all();
        $user = new User;
        $user->username = Input::get('username');
        $user->email = Input::get('email');
        $user->password = Hash::make(Input::get('password'));    
        $user = User::create($input);
        return Redirect::action("Frontend\HomeController@index");
    

    }

    //ログインまたはサインイン

    public function postSignin() {
    
        $userdata = array(
            'username' => Input::get('username'),
            'password' => Input::get('password')
        );
    
        if (Auth::attempt($userdata, true)) {
             Session::put('username', Auth::user()->username);
             return Redirect::action("Frontend\HomeController@index");
        } else {
             return Redirect::action("Frontend\UserController@getLogin")
                    ->with('message', 'Your username/password combination was incorrect')
                    ->withInput();
    }
    

私が誰かを助けたことを願っています

于 2014-11-01T01:50:22.597 に答える