Can't get Laravel registration form to store passwords with a hash Can't get Laravel registration form to store passwords with a hash laravel laravel

Can't get Laravel registration form to store passwords with a hash


Okay, so besides the fact that the code you have above won't work, you're going about this the wrong way.

Firstly, the method you're trying to do would be:

$input = Input::only(['username', 'email', 'password']);$input['password'] = Hash::make($input['password']);

The approach you have of setting the value in only won't work, and besides that, you have Hash::make('password') which will make a hash of 'password' every time, not the variable, but the word. Input::only() accepts an array of field names to return, so it uses the values of the array, not the key. The array ['password' => Hash::make('password')] has the value of the hash of the word password, not 'password'.

The best approach would be like this:

$input = Input::only(['username', 'email', 'password']);$user = User::create($input);

Then, within your User model you have:

public function setPasswordAttribute($value){    $this->attributes['password'] = Hash::make($value);}

This means that you don't have to bother with hashing, and can trust that the model will do it for you.

Also, if memory serves, Auth::login() accepts an integer, not a model, so it'd be Auth::login($newUser->id) to login the user who just registered, although I would highly recommend some sort of validation/activation via email.