Create user with encrypted password

Asked

Viewed 97 times

1

I have doubts about Laravel one of which is reflected where to insert the field:

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

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

The code of View is:

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

Of 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 to do this step in my application?

I made the same question on Soen.

  • You don’t have to tell me in the O.R. And if you have answer there before that here, you can put here the solution (preferably with your own words) and quote the source as well. Good luck!

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');
}

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

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.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.