0

How to make a hashed authentication? so made this login function for my project, and my teacher asked me to make this login with hash and bcrypt, but I have no idea about that

public function login(Request $request)
{

    $kredensil = $request->only('username', 'password');

    if (Auth::attempt($kredensil)) {

        $users = Auth::user();

        if($users->level == 'admin'){

            return redirect()->intended('admin/siswa');
            
        }

        elseif ($users->level == 'siswa') {

            return redirect()->intended('siswa/home');

        }

        return redirect('login')->with('error', 'Login gagal harap cek username dan password');
    }
    return redirect('login')->with('error', 'Login gagal harap cek username dan password');
}
Tamil Selvan C
  • 19,913
  • 12
  • 49
  • 70
jaynes
  • 1
  • 1

1 Answers1

0

Hashing algorithm can be changed via config/hashing.php.

'driver' => 'bcrypt'

When a user registers, the password is usually hashed by using Hash::make(). Most of the authentication packages does this by default.

Auth::attempt() hashes the given password behind the scene and compare it to the hashed one in the database.

P. K. Tharindu
  • 2,565
  • 3
  • 17
  • 34