Skip to content
Advertisement

passwords dont get hashed in laravel

as the title says..

My project was hashing passwords properly until recently I noticed that passwords of new users dont get hashed while it is supposed to be as I am using Hash::make and I used Hash on the top of the controller. Please Help… here is my User controller I am using laravel 5.6 if this would help…

namespace AppHttpControllersAuth;

use AppUser;
use Hash;
use AppHttpControllersController;
use IlluminateSupportFacadesValidator;
use IlluminateFoundationAuthRegistersUsers;
use IlluminateHttpRequest;
class RegisterController extends Controller
{
    use RegistersUsers;
    protected $redirectPath = '/admin';
    protected function validator(array $data)
    {
        return Validator::make($data, [
            'f_name' => 'required|string|max:255',
            'user_id' => 'required|string|max:255|unique:person',
            'm_name' => 'required|string|max:255',
            'g_name' => 'required|string|max:255',
            's_name' => 'required|string|max:255',
            'address' => 'required|string|max:255',
            'email' => 'required|string|email|max:255|unique:person',
            'field_of_study'=> 'string|max:255',
            'gender' => 'required|boolean',
            'b_date' => 'required|date|max:255',
            'type' => 'required|integer|max:3',
            'job_title' => 'string|max:255',
            'orgnaization' => 'required|string|max:255',
            'sector' => 'boolean',
            'mobile' => 'required|string|min:10', 
            'password' =>'required|string|min:10',

        ]);
    }

    protected function create(array $data)
    {
            return User::create([
            'f_name' => $data['f_name'],
            'user_id' => $data['user_id'],
            'm_name' => $data['m_name'],
            'g_name' => $data['g_name'],
            's_name' => $data['s_name'],
            'address' => $data['address'],
            'field_of_study' => $data['field_of_study'],
            'gender' => $data['gender'],
            'b_date' => $data['b_date'],
            'type' => $data['type'],
            'job_title' => $data['job_title'],
            'orgnaization' => $data['orgnaization'],
            'mobile' => $data['mobile'],
            'sector' => $data['sector'],
            'email' => $data['email'],
            'password' => Hash::make($data['password']),
        ]); 

    }

     public function register(Request $request)
     {

          if($user=User::create($request->all()))
          {
              return redirect('Admin')->with('message', 'done');
          }
            else
            {
                return redirect()->back()->with('error', 'error');
            }          
     }
}

and here is my model

protected $fillable = [
    'f_name','m_name','g_name','s_name','address','user_id','field_of_study','gender','b_date','type','job_title','orgnaization','mobile','sector', 'email', 'password',
];
    protected $hidden = [
    'password', 
];

Advertisement

Answer

use

if ($user = $this->create($request->all()))

instead of

if($user=User::create($request->all()))

You’re not calling your controller function, you’re just doing User::create. that’s why none of your data is being hashed

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement