Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 验证::尝试在Laravel 5中不工作_Php_Authentication_Laravel 5 - Fatal编程技术网

Php 验证::尝试在Laravel 5中不工作

Php 验证::尝试在Laravel 5中不工作,php,authentication,laravel-5,Php,Authentication,Laravel 5,我已经读过几十篇类似的帖子,但仍然无法让它发挥作用。我总是收到“登录失败”的消息。 这是我的用户表 CREATE TABLE users ( id int(10) unsigned NOT NULL, first_name varchar(255) COLLATE utf8_unicode_ci NOT NULL, last_name varchar(255) COLLATE utf8_unicode_ci NOT NULL, slug varchar(255) COLLATE utf8_uni

我已经读过几十篇类似的帖子,但仍然无法让它发挥作用。我总是收到“登录失败”的消息。 这是我的用户表

CREATE TABLE users (
id int(10) unsigned NOT NULL,
first_name varchar(255) COLLATE utf8_unicode_ci NOT NULL,
last_name varchar(255) COLLATE utf8_unicode_ci NOT NULL,
slug varchar(255) COLLATE utf8_unicode_ci NOT NULL,
email varchar(255) COLLATE utf8_unicode_ci NOT NULL,
password varchar(255) COLLATE utf8_unicode_ci NOT NULL,
remember_token varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
updated_at timestamp NOT NULL DEFAULT '0000-00-00 00:00:00'
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
请参阅密码字段为255,足够大,可以进行哈希运算

这是我的App\Model\User类

namespace App\Model;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    protected $fillable = ['name', 'email', 'password'];
    protected $hidden = ['password', 'remember_token'];
}
这是登录控制器

namespace App\Http\Controllers\Backend;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;

class MainController extends Controller
{
    public function getLogin()
    {
        return view('backend.login');
    }

    public function postLogin(Request $request)
    {
        if (Auth::attempt([
            'email'    => $request->input('email'),
            'password' => $request->input('password')
        ])) {
            echo 'login successful'; exit();
        }
        else {
            echo 'login failed'; exit();
        }
    }
}
插入数据库中的用户记录时,其密码设置为

Crypt::encrypt('123456')
这给了我存储在数据库中的近200个chaacter长哈希密码(这正常吗?)

我的config.app文件显示

'key' => env('APP_KEY'),
'cipher' => 'AES-256-CBC',
最后是我的config.auth文件

return [
    'defaults' => [
        'guard' => 'web',
        'passwords' => 'users',
    ],
    'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],
        'api' => [
            'driver' => 'token',
            'provider' => 'users',
        ],
    ],
    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\Model\User::class,
        ],
    ],
    'passwords' => [
        'users' => [
            'provider' => 'users',
            'email' => 'auth.emails.password',
            'table' => 'password_resets',
            'expire' => 60,
        ],
    ],
];
我试图从表单中转储$request->input('email')/$request->input('password'),一切都如预期的那样。 我试图转储查询日志,但查询似乎是正确的(“select*from users where=?limit 1,具有正确的电子邮件字段绑定”)

我还能查什么? 有没有一种方法可以“深入检查”Auth::尝试检查那里出了什么问题


任何帮助都将不胜感激。

这里的问题是您正在使用
Crypt::encrypt('123456')
设置用户密码。
Crypt
不用于此目的,因为它需要
Decrypt
才能工作,而
Auth
类中未实现此功能

在保存到数据库之前,请使用
Hash
对密码进行散列

例如:

User::create([ 
    'password' => Hash::make('123456'),
    'username' => 'hitman'
]);
您还可以通过将其添加到
user
model类中,在用户模型中进行哈希运算:

public function setPasswordAttribute($password)
{
    $salt = md5(str_random(64) . time());
    $this->attributes['password'] = \Hash::make($password);
    $this->attributes['salt'] = $salt;
}
稍后您可以简单地执行以下操作:

User::create([ 
    'password' => '123456', //hashing will be done in model
    'username' => 'hitman'
]);

这里的问题是您正在使用
Crypt::encrypt('123456')
设置用户密码。
Crypt
不用于此目的,因为它需要
Decrypt
才能工作,而
Auth
类中未实现此功能

在保存到数据库之前,请使用
Hash
对密码进行散列

例如:

User::create([ 
    'password' => Hash::make('123456'),
    'username' => 'hitman'
]);
您还可以通过将其添加到
user
model类中,在用户模型中进行哈希运算:

public function setPasswordAttribute($password)
{
    $salt = md5(str_random(64) . time());
    $this->attributes['password'] = \Hash::make($password);
    $this->attributes['salt'] = $salt;
}
稍后您可以简单地执行以下操作:

User::create([ 
    'password' => '123456', //hashing will be done in model
    'username' => 'hitman'
]);

我希望这个能帮助你

Hash::make($data['password'])

我希望这个能帮助你

Hash::make($data['password'])