Create user with encrypted password

1

I have doubts regarding Laravel one of which is reflected where to enter the field:

$password = hash::make('password');

Since I want to encrypt the password of the user creation form.

The View code is:

{{ Form::open(array('route' => 'users.store')) }}
<li>
   {{ Form::label('password', 'Confirmar Password:') }}
   {{ Form::password('password_confirmation') }}
</li>
{{Form::close()}}

Controller is:

public function store()
    {
        $input = Input::all();
        $validation = Validator::make($input, User::$rules);

        if ($validation->passes())
        {
            User::create($input);

            return Redirect::route('users.index');
        }

        return Redirect::route('users.create')
            ->withInput()
            ->withErrors($validation)
            ->with('message', 'Existem erros de validação.');
    }

How do I make this step in my application?

I made same question in SOen .

    
asked by anonymous 21.10.2014 / 17:12

2 answers

1

put the code after validation, it would look something like this

if ($validation->passes())
{
    $input['password_confirmation'] = hash::make($input['password_confirmation']);

    User::create($input);

    return Redirect::route('users.index');
}

Here we are encrypting what was typed by the user and adding the input variable, since it is what you passed it as parameter to create the user

    
23.10.2014 / 19:02
1
if ($validation->passes())
{
    $user = new User;

    $user->username = Input::get('username');
    $user->password = Hash::make(Input::get('password'));

    $user->save();

    return Redirect::route('users.index');
}

I think this is what you need, it's one of the right ways in Laravel 4.

    
10.11.2014 / 09:01