0
votes

I'm using Laravel 5.4 and using laravel auth to register and login users. Its working good.

Problem: I'm creating users from admin panel as well. But the users created from admin panel are unable to login.

Login Form is same for both form (frontend register form and admin panel user registration form). and that login form works well for users who registered using frontend form not for other.

I'm encrypting the user password in bcrypt(123456) also I've tried Hash::make(123456).

Database table is same for both users (created from frontend and created from admin panel).

 $user = new User();
 $user->name              = $request->input('name');
 $user->email             = $request->input('email');
 $user->password          = bcrypt(123456);
 $user->save();

Error I'm getting on login: These credentials do no match our record

What I should do ?

Stored record in db:

3
Show your login code.Pankit Gami
Try to use \Hash::make('123456') for the passwordNerea
I'm using the default laravel login. I haven't modified thatRizwan Saleem
@Nerea I've triend that but same issue: "These credentials do not match our records"Rizwan Saleem
If you are using default laravel auth it check the email and password, not the username, so are you login with email?Nerea

3 Answers

0
votes

If you're using this on the Controller you can follow Laravel Hashing documentation:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use App\Http\Controllers\Controller;

class UpdatePasswordController extends Controller
{
    /**
     * Update the password for the user.
     *
     * @param  Request  $request
     * @return Response
     */
    public function update(Request $request)
    {
        // Validate the new password length...

        $request->user()->fill([
            'password' => Hash::make($request->newPassword)
        ])->save();
    }
}

Pay attention to this after the namespace use Illuminate\Support\Facades\Hash; and if you want to hardcode the password replace Hash::make($request->newPassword) with Hash::make('password')

Here the link Hashing Documentation

0
votes
User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
        ]);

Try it )

0
votes

I found an answer to my problem. Auth automatically bcrypt() password fields... You don't need to bycrpt it when you're saving a user.