2015-07-10 117 views
0

我创建了一个管理界面,并在管理员和密码字段的数据库中创建了一个管理员表。在第一次尝试中,我手动创建了密码,并且我对它进行了md5加密,但是很快我就知道laravel不支持md5加密密码。无法以管理员身份登录laravel4

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

那时候,我没有创建注销功能,因为我只是测试,所以关闭了浏览器并进入第二天,突然间我无法用相同的用户名和密码登录到我的管理面板,提供未经授权的信息“您提供的用户名或密码错误!” 这让我感到吃惊,因为使用相同的用户名和密码,我可以在前一天登录到我的管理员帐户。我确信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.'); 
} 

} 

?> 

回答

0

喜在未来的路径

In app/ 
    config/ 
     auth.php 

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

+0

这是什么意思,auth.php file.make中的任何问题请清楚吗? @Lagul – RTan

0

验证文件您必须添加用于验证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, 

), 

); 
+0

那么我的**用户表会为我的最终用户发生什么?因为在我的auth.php文件中,我设置了model ='User',因为我有一个'User'模型用于我的最终用户注册。 @Lagul – RTan

+0

如果管理员是一个用户级别,使其成为模型,您应该检查该模型并熨烫您应该进行身份验证。 – Lagul