Home > Back-end >  How to match input password and database hash password in laravel 8
How to match input password and database hash password in laravel 8

Time:08-08

How to authenticate a user password from a given request in Laravel? How is the password checked against the password hash stored in the database? ** This is my Controller **

<?php

namespace App\Http\Controllers;


use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class MainController extends Controller
{
    function login1(Request $request){
      $username = $request->input('username');
      $password = $request->input('password');

      

      $data = DB::table('users')->where(['username'=>$username, 'password'=>$password])->first();
      if($data == null){
        echo "error";
    
        $notification = array(
                'message' => 'User Does not Exists!',
                'alert-type' => 'error'
            );
            return back()->with($notification);
      }
else{
    
       
            $request->session()->put('user',$data);
            return redirect('dashboard');
      
      
}
}}

CodePudding user response:

$credentials = $request->only('email', 'password');

if (Auth::attempt($credentials)) {
   // Authentication passed...
}

CodePudding user response:

like this

$encrypted = Crypt::encrypt('password_name_variable');

  • Related