无法在laravel4

时间:2015-07-10 04:43:18

标签: php mysql encryption laravel-4

我创建了一个管理界面,并在我的数据库中使用admin和password字段创建了一个管理表。在第一次尝试中,我手动创建了密码并且我将其加密了md5,但很快我就知道laravel不支持md5加密密码。

所以我决定创建哈希密码,我做的是,从我的最终用户注册面板,我注册了一个新用户,它自动在数据库中创建一个哈希密码,我复制该密码并粘贴到我的管理员表的密码字段,只有这样我才能登录我的管理面板。

在那段时间里,我没有创建注销功能,因为我只是在测试,所以关闭浏览器并在第二天进入,突然间我无法登录我的管理面板用户名和密码,提供未经授权的消息"您提供的用户名或密码错误!" 这让我很吃惊,因为使用相同的用户名和密码,我能够在前一天登录我的管理员帐户。我确信在laravel中出现了问题,或者我的代码中可能存在一些问题,但无法弄明白。这是文件夹结构和我的代码

src/
   app/
      controllers/
                 admin/
                      AdminController.php
      model/
           admin.php
      routes.php 
      filters.php

admin.php的

<?php

use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;

class \Admin extends Eloquent implements UserInterface, RemindableInterface    {



    public function getRememberToken()
    {
        return $this->remember_token;
    }

    public function setRememberToken($value)
    {
        $this->remember_token = $value;
    }

    public function getRememberTokenName()
    {
        return 'remember_token';
    }

    protected $table = 'admins';

    protected $fillable=array
    (   'username',
        'password'

    );



    use UserTrait, RemindableTrait;

AdminController.php

<?php

namespace Admin;

class AdminController extends \BaseController{

    public function AdminLogin(){
        return \View::make('admin.login');
    }

public function AdminLoginPost(){

    $auth=\Auth::attempt(array(

          'username' => \Input::get('username'),
          'password' => \Input::get('password')
            ));

    if($auth){

        return \Redirect::intended('marriage-admin');

    }else{

        return \Redirect::route('admin')->with('global','The username or password you provided is wrong!');
    }
    return \Rediret::route('admin')->with('global','Please Review Your Admin Database.');
}

}

?>

2 个答案:

答案 0 :(得分:0)

你好,在下一个路径

In app/
     config/
        auth.php

您可以配置laravel创建验证时引用的驱动程序,模型和表。

答案 1 :(得分:0)

auth文件必须将用于验证laravel的模型添加到引用将要执行的表中。例如,在您的情况下:

<?php

return array(

/*
|--------------------------------------------------------------------------
| Default Authentication Driver
|--------------------------------------------------------------------------
|
| This option controls the authentication driver that will be utilized.
| This driver manages the retrieval and authentication of the users
| attempting to get access to protected areas of your application.
|
| Supported: "database", "eloquent"
|
*/

'driver' => 'eloquent',

/*
|--------------------------------------------------------------------------
| Authentication Model
|--------------------------------------------------------------------------
|
| When using the "Eloquent" authentication driver, we need to know which
| Eloquent model should be used to retrieve your users. Of course, it
| is often just the "User" model but you may use whatever you like.
|
*/

'model' => 'admin',

/*
|--------------------------------------------------------------------------
| Authentication Table
|--------------------------------------------------------------------------
|
| When using the "Database" authentication driver, we need to know which
| table should be used to retrieve your users. We have chosen a basic
| default value but you may easily change it to any table you like.
|
*/

'table' => 'your table here',

/*
|--------------------------------------------------------------------------
| Password Reminder Settings
|--------------------------------------------------------------------------
|
| Here you may set the settings for password reminders, including a view
| that should be used as your password reminder e-mail. You will also
| be able to set the name of the table that holds the reset tokens.
|
| The "expire" time is the number of minutes that the reminder should be
| considered valid. This security feature keeps tokens short-lived so
| they have less time to be guessed. You may change this as needed.
|
*/

'reminder' => array(

    'email' => 'emails.auth.reminder',

    'table' => 'password_reminders',

    'expire' => 120,

),

);