0

I have laravel 5.2 project and need to add Authentication, but I need to connect it to my table, that has Username and Password, also change default email/password to username/password. Also in my table passwords are not crypted.

I have change login.blade.php file from email field to username.

Also change user.php model:

 protected $table = 'LoginTable';

Also change AuthController.php. Add this:

 protected $username = 'username';

and change validator and create methods:

 return Validator::make($data, [
        'username' => 'required|max:255',
        'password' => 'required|min:6|confirmed',
    ]);
 return User::create([
        'username' => $data['username'],
        'password' => bcrypt($data['password']),
    ]);

But I cant login.It's saying 'These credentials do not match our records.'. How can I check what is the problem? Can anyone help me with this issue?

UPDATE

I have change password to hashed password, but still cant make auth work.It is still saying: These credentials do not match our records.

I want to mention that in Database I have only username and password, and dont have name and email.

2
  • Have you gone through docs? Here is how you can manually authenticate a user. docs Commented Nov 23, 2016 at 9:51
  • Manual authentication is probably not the best idea. There's a lot of extra goodies you lose by doing that. Commented Nov 23, 2016 at 9:54

1 Answer 1

1

If you are trying to authenticate with an existing user with an unencrypted password it won't work.

Laravel auth requires all passwords to be encrypted to pass validation. So first you'll need to update the database and encrypt all passwords with the same encryption key defined in config/app.php or in the .env file.

Also as a rule of thumb you should never ever keep clear text passwords in the database.

Sign up to request clarification or add additional context in comments.

3 Comments

thanks for your resposne. Are other changes correct? just need to encrypt password? One more think, in app.php I found 'cipher' => 'AES-256-CBC', and in env.file I found APP_KEY=base64:y6raQpepxEWDZVsX6gwhRuRvOxPoKaj1SJUvzzPV/U0=. Which one is the one I need?
Yes, all other changes are correct. The setting in the config/app.php is the one above 'cipher', the one named 'key' which by default reads the setting APP_KEY from the .env file.
You just need to bcrypt() all your passwords, this will use your APP_KEY.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.