Хеширование паролей пользователей из csv import - PullRequest
0 голосов
/ 27 февраля 2020

нужна помощь. Я не могу решить большую проблему, я хочу иметь sh пароль всех пользователей, когда я импортирую файл csv в свою базу данных. Мой файл CSV загружен хорошо и действительно работает, но пароль никогда не был sh. Мой код:

UserController. php:

publi c function users_data_store () {

    $inputs = Input::all();
    $validation = Validator::make($inputs, $this->file_rules);
    if ($validation->fails()) {
        return Redirect::back()->withInput()->withErrors($validation);
    } 

    else {

        if (Input::hasFile('csv_file')) {

            $extension = Input::file('csv_file')->getClientOriginalExtension();
            if ($extension == "csv" OR $extension == "CSV") {

                $file = Input::file('csv_file')->getRealPath();

                function csv_to_array($filename='', $delimiter=';')
                {
                    if(!file_exists($filename) || !is_readable($filename))
                        return FALSE;

                    $header = NULL;
                    $data = array();
                    if (($handle = fopen($filename, 'r')) !== FALSE)
                    {
                        while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE)
                        {
                            if(!$header)
                                $header = $row;
                            else
                                $data[] = array_combine($header, $row);
                        }
                        fclose($handle);
                    }
                    /*$request->user()->fill([
                         'password' => Hash::make($request->password) // Hashing passwords
                      ])->save();*/

                    return $data;   
             }
                $areas = csv_to_array($file);
                DB::table('users')->insert($areas); 
                $path = Session::get('language');
                return Redirect::back()->with('success', Lang::get($path.'.users_import_success'));

            } else {
                return Redirect::back();
            }


        }

    }

}

Моя модель - Пользователь. php:

<?php

use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;

class User extends Eloquent implements UserInterface, RemindableInterface {

    use UserTrait, RemindableTrait;

    protected $guarded = ['id', 'created_at'];

    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'users';

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = array('password', 'remember_token');


    public function children()
    {
        return $this->hasMany('User', 'guardian_id');
    }


}

Мои маршруты - маршрут. php:

   Route::post('admin/user_data/store', ['as'=>'users_data_store', 'uses'=>'UserController@users_data_store']);

Спасибо за помощь.

1 Ответ

0 голосов
/ 27 февраля 2020
use Illuminate\Support\Facades\Hash;

Вставьте верхнюю часть кода в ваш файл, а затем вставьте пароль ha sh перед вставкой. Используйте код ниже.

$areas = csv_to_array($file);
$areas['password'] = Hash::make($areas['password']);
DB::table('users')->insert($areas); 
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...