'SQLSTATE[HY000] [2002] Connection refused select count(*) as aggregate from `admins` where ( `username` = admin and `password` = admin )

 /  Http  /  Controllers  /  AdminController .php   : 24

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Models\Admin;

class AdminController extends Controller

{

//Dashboard

public function index(){

    return view('index');

}

 //login

 public function login(){

    return view('login');

}

 //Submit_login

 public function submit_login(Request $request){

     $request->validate([

         'username'=>'required',

         'password'=>'required'

 ]);

 $checkAdmin=Admin::where(['username'=>$request->username,'password'=>$request->password])->count();

 if($checkAdmin>0){

     return redirect('admin');

 }



 }

}



Solution 1:[1]

You can not check passwords directly from the database because of password hashing.

You should try:

$checkAdmin = AdminUser::where('username',$request->username)->first();

if (Hash::check($request->password, $checkAdmin->password)) {
    return redirect('admin');
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Abbas Vaghela