如标题所示。
我的项目一直在正确地对密码进行哈希处理,直到最近我注意到新用户的密码没有被哈希处理,而这应该是因为我正在使用Hash :: make,并且在控制器顶部使用了Hash。请帮忙... 这是我的用户控制器 我正在使用laravel 5.6如果这可以帮助...
namespace App\Http\Controllers\Auth;
use App\User;
use Hash;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Http\Request;
class RegisterController extends Controller
{
use RegistersUsers;
protected $redirectPath = '/admin';
protected function validator(array $data)
{
return Validator::make($data, [
'f_name' => 'required|string|max:255',
'user_id' => 'required|string|max:255|unique:person',
'm_name' => 'required|string|max:255',
'g_name' => 'required|string|max:255',
's_name' => 'required|string|max:255',
'address' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:person',
'field_of_study'=> 'string|max:255',
'gender' => 'required|boolean',
'b_date' => 'required|date|max:255',
'type' => 'required|integer|max:3',
'job_title' => 'string|max:255',
'orgnaization' => 'required|string|max:255',
'sector' => 'boolean',
'mobile' => 'required|string|min:10',
'password' =>'required|string|min:10',
]);
}
protected function create(array $data)
{
return User::create([
'f_name' => $data['f_name'],
'user_id' => $data['user_id'],
'm_name' => $data['m_name'],
'g_name' => $data['g_name'],
's_name' => $data['s_name'],
'address' => $data['address'],
'field_of_study' => $data['field_of_study'],
'gender' => $data['gender'],
'b_date' => $data['b_date'],
'type' => $data['type'],
'job_title' => $data['job_title'],
'orgnaization' => $data['orgnaization'],
'mobile' => $data['mobile'],
'sector' => $data['sector'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
}
public function register(Request $request)
{
if($user=User::create($request->all()))
{
return redirect('Admin')->with('message', 'done');
}
else
{
return redirect()->back()->with('error', 'error');
}
}
}
这是我的模特
protected $fillable = [
'f_name','m_name','g_name','s_name','address','user_id','field_of_study','gender','b_date','type','job_title','orgnaization','mobile','sector', 'email', 'password',
];
protected $hidden = [
'password',
];
答案 0 :(得分:2)
使用
if ($user = $this->create($request->all()))
代替
if($user=User::create($request->all()))
您不是在调用控制器函数,而是在执行User :: create。这就是为什么您的任何数据都不会被散列的原因
答案 1 :(得分:0)
也许这段代码可以帮助您:
$_SERVER['PHP_SELF']