Skip to content
Advertisement

Can laravel make password encryption like mysql password() function?

how do I make password encryption on Laravel PHP to look like Mysql password() encryption? is there a way to do that? so I can create user to MySql using query on Laravel eloquent, and logged in to MySql using the user I create with Laravel?

Advertisement

Answer

No you can’t. because we can’t get MySQL user tables using eloquent (AFAIK)

But you can create mysql user using query (but you need to set DB config to root/admin user first)

example:

$user = "youruser";
$pass = "yourpassword";

DB::statement(DB::raw("CREATE USER '$user'@'localhost' IDENTIFIED BY '$pass'");
DB::statement(DB::raw("GRANT ALL PRIVILEGES ON * . * TO '$user'@'localhost'");

and to use as your app db config:

Config::set('database.connections.mysql.user', $user);
Config::set('database.connections.mysql.password', $yourpassword);

You can do anything with new created user after that. example to call migration:

Artisan::call("migrate --database=mysql");
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement