Reputation: 2255
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
Reputation: 4023
You can create the password that you want via php artisan tinker
:
php artisan tinker
.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
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
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