0

I have problem to my apps this input password hash.

    $simpan['password']=Request::input('password');

how make hash in my code?

ivan setiadi
  • 107
  • 1
  • 3
  • 8

2 Answers2

1

You have two options

Call make method on Hash facade Hash::make('string_here')

Or use global helper function bcrypt('string_here')

Example:

//Hash facade example
$simpan['password']= Hash::make(Request::input('password'));

//bcrypt global helper function
$simpan['password']= bcrypt(Request::input('password'));

Resource:

https://laravel.com/docs/5.1/hashing

devnull
  • 1,848
  • 2
  • 15
  • 23
0

In Laravel we can handle it a very intelligent and efficient way by using Mutators in Model Class.

use Illuminate\Support\Facades\Hash;

class User extends Authenticatable
{

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];    


    // Password hassing by default to all new users,
    public function setPasswordAttribute($pass)
    {
        // here you can make any opration as you like
        $this->attributes['password'] = Hash::make($pass);
    }

}

now you don't have to do manually password hashing every time just store user in table by create or any other method

$created_user = User::create(request()->all());
dipenparmar12
  • 3,042
  • 1
  • 29
  • 39