Php 散列一个密码,但仍然只需使用Eloquents::create($input)

Php 散列一个密码,但仍然只需使用Eloquents::create($input),php,security,laravel,hash,eloquent,Php,Security,Laravel,Hash,Eloquent,将Laravel4.2用于用户系统并进行注册 验证通过后,我会执行以下操作: User::create($input); return Redirect::to('/'); 它正确地存储了我的用户,但它有一个未哈希的密码,因为它刚刚传入: $Input = Input::all(); 我不想手动将所有字段添加到create方法中,有没有办法仍然只传入$input,而散列密码部分 我还应该在Laravel上使用哈希或加密作为密码吗?您不需要添加所有字段。一个选项是从输入数组中只检索密码字段,并

将Laravel4.2用于用户系统并进行注册

验证通过后,我会执行以下操作:

User::create($input);
return Redirect::to('/');
它正确地存储了我的用户,但它有一个未哈希的密码,因为它刚刚传入:

$Input = Input::all();
我不想手动将所有字段添加到create方法中,有没有办法仍然只传入$input,而散列密码部分


我还应该在Laravel上使用哈希或加密作为密码吗?

您不需要添加所有字段。一个选项是从输入数组中只检索密码字段,并用哈希密码替换它

$input = \Input::all();
// get the password and save it with its hash
$input['password'] = \Hash::make($input['password']);
User::create($input);
return Redirect::to('/');

您不需要添加所有字段。一个选项是从输入数组中只检索密码字段,并用哈希密码替换它

$input = \Input::all();
// get the password and save it with its hash
$input['password'] = \Hash::make($input['password']);
User::create($input);
return Redirect::to('/');

您使用的是
elount
模型,因此可以通过模型本身轻松地转换密码属性

只需将此函数添加到您的
雄辩
模型中,然后执行您正在执行的任何操作,无需更改
$input
数组

public function setPasswordAttribute($password)
{
    $this->attributes['password'] = \Hash::make($password);
}

通过这种方式,您可以对请求数据属性应用任何类型的修改。

您使用的是
Eloquent
模型,因此您可以轻松地通过模型本身转换密码属性

只需将此函数添加到您的
雄辩
模型中,然后执行您正在执行的任何操作,无需更改
$input
数组

public function setPasswordAttribute($password)
{
    $this->attributes['password'] = \Hash::make($password);
}
这样,您可以对请求数据属性应用任何类型的修改。

有意义:)谢谢。有意义:)谢谢。