Laravel Auth :: attempt () is always false?

I recently started learning Laravel (the PHP MVC framework) and I had a lot of problems with user authentication: Auth :: attempt ($ credentials).

Below are my code snippets. In my mySQL database, I have an entry with the following key => values: id => 1, username => 'admin', password => 'admin', created_at => 0000-00-00 00:00:00, updated_at => 0000-00-00 00:00:00

The validator passes, but the Auth attempt: the attempt always fails.

If the code below and my little explanation is not enough, let me know !:-)

routes.php:

Route::get('login', ' AuthController@showLogin '); Route::post('login', ' AuthController@postLogin '); 

AuthController:

 public function showLogin(){ if(Auth::check()){ //Redirect to their home page } //Not logged in return View::make('auth/login'); } public function postLogin(){ $userData = array( 'username' => Input::get('username'), 'password' => Input::get('password') ); $reqs = array( 'username' => 'Required', 'password' => 'Required' ); $validator = Validator::make($userData, $reqs); if($validator->passes() && Auth::attempt($userData)){ return Redirect::to('home'); } return Redirect::to('login')->withInput(Input::except('password')); } 
+4
source share
1 answer

I believe that the try () method will have a hash password that is sent. Seeing how your password to enter the database is the "administrator" in clear text, this will not work. Save the password using Hash :: make ($ password); and I believe that your problem should be resolved.

+17
source

Source: https://habr.com/ru/post/1494856/


All Articles