MakkyNZ
MakkyNZ

Reputation: 2255

Manually creating laravel hash directly in SQL

I have a site where user passwords are hashed using Laravel's Hash::make() function.
I now have a need to manually create user's directly in the DB (MySQL). Is there a way I can create the hashed password for the user using just raw SQL?

Upvotes: 6

Views: 10470

Answers (3)

Panagiotis Koursaris
Panagiotis Koursaris

Reputation: 4023

You can create the password that you want via php artisan tinker:

  1. Open the terminal on the root of your project.
  2. Then write php artisan tinker.
  3. Then echo Hash::make('password');

You will see the hashed password. You can do whatever you want with that password, even with sql query directly.

Upvotes: 24

Jirennor
Jirennor

Reputation: 1289

You could use the DB Seed option in Laravel and add your users that way. Via the DB seed you can use the hash method to hash the passwords.

class UserTableSeeder extends Seeder {

    public function run()
    {  
        DB::table('users')->delete();
            User::create(array(
                'username' => 'user',
                'password' => Hash::make('password')
            ));
    }
}

But if can only use raw SQL I dont have a solution for you.

For more information about DB Seed see the following page. http://laravel.com/docs/4.2/migrations#database-seeding

Upvotes: 0

Joel Hinz
Joel Hinz

Reputation: 25414

Not really, I'm afraid. Laravel uses Bcrypt, which isn't available in MySQL. In addition, it's a bad practice to do it in raw SQL, because the passwords might end up in server query logs. Sorry. :/

Upvotes: 5

Related Questions