2017-01-26 4 views
1

일치하지 않습니다. 나는 몇몇 사용자, 역할, role_user, 권한 및 permission_role을 시드를 사용하여 내 DB에 삽입하지만 DB에 이미 기록 된 전자 메일 및 암호를 사용하여 로그인하려고하면 다음 자격이 있습니다. 이러한 자격 증명이 우리 레코드와 일치하지 않습니다. 이러한 자격 증명은 내가, 내가 다른 사용자와 다른 역할을 가지고있는 laravel와 응용 프로그램을 가지고 우리의 기록

은 UserTableSeeder입니다 :

public function run() 
{ 
    // 

    $user = [ 
     [ 
      'name' => 'admin', 
      'email' => '[email protected]', 
      'password' => 'passwordadmin' 
     ], 
     [ 
      'name' => 'president', 
      'email' => '[email protected]', 
      'password' => 'passwordpresident' 
     ], 
     [ 
      'name' => 'utilisateur1', 
      'email' => '[email protected]', 
      'password' => 'passworduser' 
     ], 
     [ 
      'name' => 'utilisateur2', 
      'email' => '[email protected]', 
      'password' => 'passworduser' 
     ] 
    ]; 

    foreach ($user as $key => $value) { 
     User::create($value); 
    } 
} 

RoleTableSeeder :

public function run() 
{ 
    // 

    $role = [ 
     [ 
      'name' => 'admin', 
      'display_name' => 'Administrateur', 
      'description' => 'Administrateur du système' 
     ], 
     [ 
      'name' => 'president', 
      'display_name' => 'Président', 
      'description' => 'President de la commune' 
     ], 
     [ 
      'name' => 'utilisateur_normal', 
      'display_name' => 'membre du conseil', 
      'description' => 'membre du conseil' 
     ] 
    ]; 

    foreach ($role as $key => $value) { 
     Role::create($value); 
    } 
} 

RoleUserTableSeeder : 내가 가지고있는

public function run() 
{ 
    // 

    DB::table('role_user')->insert([ 
     [ 'user_id' => 6, 'role_id' => 4 ], 
     [ 'user_id' => 7, 'role_id' => 5 ], 
     [ 'user_id' => 8, 'role_id' => 6 ], 
     [ 'user_id' => 9 , 'role_id' => 6 ],    
    ]); 

} 

모델 : 사용자, 역할, 권한.

아무쪼록 바랍니다.

+2

데이터베이스에 암호화 된 암호를 삽입해야합니다 : 'password'=> bcrypt ('passworduser'), ' – Troyer

답변

1

Troyer 말했듯이, 당신은 bcrypt로 해시해야합니다. Laravel은 \ Hash :: make ($ str)와 함께 편리한 래퍼를 제공합니다.

는 일반 텍스트로 암호를 가지고 매우 나쁜 관행이다.

당신은이처럼 시더를 실행해야합니다 : 당신은 더 시더를 볼 수 있습니다

public function run() 
{ 
    // 

$user = [ 
    [ 
     'name' => 'admin', 
     'email' => '[email protected]', 
     'password' => bcrypt('passwordadmin') 
    ], 
    [ 
     'name' => 'president', 
     'email' => '[email protected]', 
     'password' => bcrypt('passwordpresident') 
    ], 
    [ 
     'name' => 'utilisateur1', 
     'email' => '[email protected]', 
     'password' => bcrypt('passworduser') 
    ], 
    [ 
     'name' => 'utilisateur2', 
     'email' => '[email protected]', 
     'password' => bcrypt('passworduser') 
    ] 
]; 

foreach ($user as $key => $value) { 
    User::create($value); 
} 
} 

: 그것은 당신이 당신의 데이터베이스에 암호 해시되지 않습니다 보인다

public function run() 
{ 
    $users = [ 
     [ 
      'name' => 'admin', 
      'email' => '[email protected]', 
      'password' => \Hash::make('passwordadmin') // Hash them in order to make use of \Auth library (and more importantly, in order not to be a dick to your users) 
     ], 
     [ 
      'name' => 'president', 
      'email' => '[email protected]', 
      'password' => \Hash::make('passwordpresident') 
     ], 
     [ 
      'name' => 'utilisateur1', 
      'email' => '[email protected]', 
      'password' => \Hash::make('passworduser') 
     ], 
     [ 
      'name' => 'utilisateur2', 
      'email' => '[email protected]', 
      'password' => \Hash::make('passworduser') 
     ] 
    ]; 
    User::create($users); // Import them with 1 query for performance 
} 
2

을, 당신은 bycript를 사용할 필요가 예 : oficial seeder Laravel documentation.

+0

당신이 맞습니다 전자 문제는 해싱 이었지만 bcrypt를 사용하면 문제가 해결되지 않았습니다. 대신 "\ Hash :: make ('passwordadmin')"를 사용했습니다. 당신이 – Naj

+1

@Naj이 esencially'\ 해시 ::) ('bcrypt)을 (만들기'와 감사'그냥 내가 그것을 좋아,'해시 ::') (확인 전화 같은,'bcrypt()'인 Laravel 도우미 기능입니다 훨씬 더 깨끗해 보이기 때문에 더 :) – Troyer