davidvera
davidvera

Reputation: 1489

Import database with password Laravel

I have an admin table with : id, name, surname, email and password fields... I have to import into a Laravel database those information from another database where the passwords are not hashed.

If i'd like to import datas i should write :

INSERT INTO admins (name, surname, email, password)
VALUES (myName, mySurname, myEmail, myPassword);

I wonder how i can Hash the password values ? Is there a mysql "methop" which allow it ? Thanks for your help

Upvotes: 1

Views: 591

Answers (3)

davidvera
davidvera

Reputation: 1489

I simply used another laravel install where i installed iseed

composer require orangehill/iseed

then i imported my database into a database and then created a seeder from an existing table

php artisan iseed admins

Then php artisan make:seeder AdminsTableSeeder

From then i just made a find and replace ...

'password' => 'mypassword', 

is replaced by :

'password' => bcrypt('mypassword'), 

Upvotes: 2

user320487
user320487

Reputation:

Laravel has a helper method to hash:

bcrypt('password')

DB::insert('insert into admins (name, surname, email, password) values (?, ?, ?,?)', [$myName, $mySurname, $myEmail, bcrypt($myPassword)]);

As well as a facade, Hash

Hash::make('password')

DB::insert('insert into admins (name, surname, email, password) values (?, ?, ?,?)', [$myName, $mySurname, $myEmail, Hash::make($myPassword)]);

Upvotes: 2

Jasper Helmich
Jasper Helmich

Reputation: 751

Make a php scrypt. That handles the hashing for you.

You could bcrypt the password and then put it in your query.

But since you are using laravel what you could do is make a seeder

https://laravel.com/docs/5.5/seeding

Then with hashing

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

should give you a headstart

Upvotes: 1

Related Questions