1

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

3 Answers 3

2

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)]);
Sign up to request clarification or add additional context in comments.

Comments

2

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'), 

Comments

1

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

1 Comment

I found out a solution thanks to your comment ! I used iseed and i solved my problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.