duandou8120 2017-01-12 12:11
浏览 15

用户详细信息更新和安全控制器

I have started to learn Laravel 5.* and currently I'm working on some basic admin panel. Create users/delte/edit etc.

I've got this for update user details

public function update( UserRequest $request){

    $user = User::find( $request['id'] );

    $hasuser = User::where('email','=',$request['email'])->where('id','!=',$request['id'])->first();
    if($hasuser){
        $request->session()->flash('alert-error','User with given email address already exist. Plese try with another email address!!.');
        return redirect()->route('admin.users'); 
    }

    $user->name =  $request['name'];
    $user->email =  $request['email'];
    $user->phone =  $request['phone'];
    $user->role =  $request['role'];

    if(!empty($request['password'])){
        $password = bcrypt($request['password']);
        $user->password = $password;    
    }

    if($user->save())
        $request->session()->flash('alert-success','User updated successfully.');
    else
        $request->session()->flash('alert-error','Can not update User now. Please try again!!.');

    return redirect()->route('admin.users');
}

What I'm not sure is the query

$hasuser = User::where('email','=',$request['email'])->where('id','!=',$request['id'])->first();

Is it good from security and sql injection point of view this variable there i.e. $request['email'], $request['id']

If not can you show me what is a good approach here?

  • 写回答

1条回答 默认 最新

  • dphg63476 2017-01-12 12:48
    关注

    Laravel's Eloquent ORM uses PDO binding to avoid SQL injection, but that's not to say it's not good practice to validate user input before you do anything with it.

    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类