I try to authenticate using a custom table from database.
Table name is kullanicilar and the fields I use for the authentication are eposta and sifre respectively.
My session controller class is like this:
class OturumDenetcisi extends Controller { public function kaydet(Request $request) { if (!\Auth::attempt(['eposta' => $request->eposta, 'password' => $request->sifre])) { return back(); } return redirect()->home(); } // ... } Also in user model I have
# In user model public function getAuthPassword () { return $this->sifre; } When I try to authenticate user nothing happens. It takes me back.
Here is the dd ($request->all()); output inside kaydet function which tries to store a new session.
array:3 [▼ "_token" => "KfbftPRMVkm4bBIWo8WoICOHmaDyvRpDhF8Wk4zq" "eposta" => "[email protected]" "sifre" => "a123" ] UPDATE : [SOLVED]
After saving the passwords to database using hashing methods now it works as excepted. Here is the complete session controller:
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Kullanici; use Illuminate\Support\Facades\Hash; class OturumDenetcisi extends Controller { public function __construct() { $this->middleware('guest', ['except' => 'cikisYap']); } public function olustur() { return view('oturumlar.olustur'); } public function kaydet(Request $request) { if (!\Auth::attempt(['eposta' => $request->eposta, 'password' => $request->sifre])) { return back(); } return redirect()->home(); } public function cikisYap() { auth()->logout(); return redirect('/'); } }
Hash::functions, so passwords should at the very least be stored as$model->password = \Hash::make("password");There are also packages available for Laravel which handles the Auth stuff automatically; consider researching that too.