Skip to content

Commit ce2d2ea

Browse files
authored
Merge pull request #5479 from Laravel-Backpack/remove-bcrypt()-calls-use-Hash
Remove bcrypt() calls use Hash
2 parents b7dca56 + 159609e commit ce2d2ea

File tree

5 files changed

+36
-32
lines changed

5 files changed

+36
-32
lines changed

phpunit.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
</source>
3636
<php>
3737
<env name="APP_ENV" value="testing"/>
38-
<env name="BCRYPT_ROUNDS" value="4"/>
38+
<env name="BCRYPT_ROUNDS" value="12"/>
3939
<env name="CACHE_DRIVER" value="array"/>
4040
<env name="DB_CONNECTION" value="sqlite"/>
4141
<env name="DB_DATABASE" value=":memory:"/>

src/app/Http/Controllers/Auth/RegisterController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Http\Request;
88
use Illuminate\Routing\Controller;
99
use Illuminate\Support\Facades\Cookie;
10+
use Illuminate\Support\Facades\Hash;
1011
use Illuminate\Support\Facades\Validator;
1112

1213
class RegisterController extends Controller
@@ -76,7 +77,7 @@ protected function create(array $data)
7677
return $user->create([
7778
'name' => $data['name'],
7879
backpack_authentication_column() => $data[backpack_authentication_column()],
79-
'password' => bcrypt($data['password']),
80+
'password' => Hash::make($data['password']),
8081
]);
8182
}
8283

tests/Unit/CrudPanel/CrudPanelCreateTest.php

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Faker\Factory;
1414
use Illuminate\Database\Eloquent\Relations\Relation;
1515
use Illuminate\Support\Arr;
16+
use Illuminate\Support\Facades\Hash;
1617

1718
/**
1819
* @covers Backpack\CRUD\app\Library\CrudPanel\Traits\Create
@@ -132,7 +133,7 @@ public function testCreate()
132133
$inputData = [
133134
'name' => $faker->name,
134135
'email' => $faker->safeEmail,
135-
'password' => bcrypt($faker->password()),
136+
'password' => Hash::make($faker->password()),
136137
];
137138

138139
$entry = $this->crudPanel->create($inputData);
@@ -152,7 +153,7 @@ public function testCreateWithOneToOneRelationship()
152153
$inputData = [
153154
'name' => $faker->name,
154155
'email' => $faker->safeEmail,
155-
'password' => bcrypt($faker->password()),
156+
'password' => Hash::make($faker->password()),
156157
'accountDetails' => [
157158
'nickname' => $account_details_nickname,
158159
'profile_picture' => 'test.jpg',
@@ -184,7 +185,7 @@ public function testCreateWithOneToOneRelationshipUsingRepeatableInterface()
184185
$inputData = [
185186
'name' => $faker->name,
186187
'email' => $faker->safeEmail,
187-
'password' => bcrypt($faker->password()),
188+
'password' => Hash::make($faker->password()),
188189
'accountDetails' => [
189190
['nickname' => $account_details_nickname, 'profile_picture' => 'test.jpg'],
190191
],
@@ -251,7 +252,7 @@ public function testCreateWithManyToManyRelationship()
251252
$inputData = [
252253
'name' => $faker->name,
253254
'email' => $faker->safeEmail,
254-
'password' => bcrypt($faker->password()),
255+
'password' => Hash::make($faker->password()),
255256
'remember_token' => null,
256257
'roles' => [1, 2],
257258
];
@@ -336,7 +337,7 @@ public function testCreateHasOneRelations()
336337
$inputData = [
337338
'name' => $faker->name,
338339
'email' => $faker->safeEmail,
339-
'password' => bcrypt($faker->password()),
340+
'password' => Hash::make($faker->password()),
340341
'remember_token' => null,
341342
'roles' => [1, 2],
342343
'accountDetails' => [
@@ -398,7 +399,7 @@ public function testMorphToManySelectableRelationship()
398399
$inputData = [
399400
'name' => $faker->name,
400401
'email' => $faker->safeEmail,
401-
'password' => bcrypt($faker->password()),
402+
'password' => Hash::make($faker->password()),
402403
'remember_token' => null,
403404
'bills' => [1],
404405
];
@@ -434,7 +435,7 @@ public function testMorphToManyCreatableRelationship()
434435
$inputData = [
435436
'name' => $faker->name,
436437
'email' => $faker->safeEmail,
437-
'password' => bcrypt($faker->password()),
438+
'password' => Hash::make($faker->password()),
438439
'remember_token' => null,
439440
'recommends' => [
440441
[
@@ -492,7 +493,7 @@ public function testBelongsToManyWithPivotDataRelationship()
492493
$inputData = [
493494
'name' => $faker->name,
494495
'email' => $faker->safeEmail,
495-
'password' => bcrypt($faker->password()),
496+
'password' => Hash::make($faker->password()),
496497
'remember_token' => null,
497498
'superArticles' => [
498499
[
@@ -560,7 +561,7 @@ public function testCreateHasOneWithNestedRelationsRepeatableInterface()
560561
$inputData = [
561562
'name' => $faker->name,
562563
'email' => $faker->safeEmail,
563-
'password' => bcrypt($faker->password()),
564+
'password' => Hash::make($faker->password()),
564565
'remember_token' => null,
565566
'roles' => [1, 2],
566567
'accountDetails' => [
@@ -630,7 +631,7 @@ public function testCreateBelongsToFake()
630631
$inputData = [
631632
'name' => $faker->name,
632633
'email' => $faker->safeEmail,
633-
'password' => bcrypt($faker->password()),
634+
'password' => Hash::make($faker->password()),
634635
'remember_token' => null,
635636
'bang_relation_field' => 1,
636637
];
@@ -689,7 +690,7 @@ public function testCreateHasOneWithNestedRelations()
689690
$inputData = [
690691
'name' => $faker->name,
691692
'email' => $faker->safeEmail,
692-
'password' => bcrypt($faker->password()),
693+
'password' => Hash::make($faker->password()),
693694
'remember_token' => null,
694695
'roles' => [1, 2],
695696
'accountDetails' => [
@@ -734,7 +735,7 @@ public function testCreateHasOneWithNestedRelations()
734735
$inputData = [
735736
'name' => $faker->name,
736737
'email' => $faker->safeEmail,
737-
'password' => bcrypt($faker->password()),
738+
'password' => Hash::make($faker->password()),
738739
'remember_token' => null,
739740
'roles' => [1, 2],
740741
'accountDetails' => [
@@ -778,7 +779,7 @@ public function testMorphOneRelationship()
778779
$inputData = [
779780
'name' => $faker->name,
780781
'email' => $faker->safeEmail,
781-
'password' => bcrypt($faker->password()),
782+
'password' => Hash::make($faker->password()),
782783
'remember_token' => null,
783784
'comment' => [
784785
'text' => 'some test comment text',
@@ -814,7 +815,7 @@ public function testMorphManyCreatableRelationship()
814815
$inputData = [
815816
'name' => $faker->name,
816817
'email' => $faker->safeEmail,
817-
'password' => bcrypt($faker->password()),
818+
'password' => Hash::make($faker->password()),
818819
'remember_token' => null,
819820
'stars' => [
820821
[
@@ -867,7 +868,7 @@ public function testHasManyCreatableRelationship()
867868
$inputData = [
868869
'name' => $faker->name,
869870
'email' => $faker->safeEmail,
870-
'password' => bcrypt($faker->password()),
871+
'password' => Hash::make($faker->password()),
871872
'remember_token' => null,
872873
'universes' => [
873874
[
@@ -952,7 +953,7 @@ public function testHasManySelectableRelationshipWithoutForceDelete()
952953
$inputData = [
953954
'name' => $faker->name,
954955
'email' => $faker->safeEmail,
955-
'password' => bcrypt($faker->password()),
956+
'password' => Hash::make($faker->password()),
956957
'remember_token' => null,
957958
'planets' => [1, 2],
958959
];
@@ -987,7 +988,7 @@ public function testHasManySelectableRelationshipRemoveAllRelations()
987988
$inputData = [
988989
'name' => $faker->name,
989990
'email' => $faker->safeEmail,
990-
'password' => bcrypt($faker->password()),
991+
'password' => Hash::make($faker->password()),
991992
'remember_token' => null,
992993
'planets' => [1, 2],
993994
];
@@ -1052,7 +1053,7 @@ public function testHasManyWithRelationScoped()
10521053
$inputData = [
10531054
'name' => $faker->name,
10541055
'email' => $faker->safeEmail,
1055-
'password' => bcrypt($faker->password()),
1056+
'password' => Hash::make($faker->password()),
10561057
'remember_token' => null,
10571058
'incomes' => [
10581059
[
@@ -1141,7 +1142,7 @@ public function testHasManySelectableRelationshipWithFallbackId()
11411142
$inputData = [
11421143
'name' => $faker->name,
11431144
'email' => $faker->safeEmail,
1144-
'password' => bcrypt($faker->password()),
1145+
'password' => Hash::make($faker->password()),
11451146
'remember_token' => null,
11461147
'planets' => [1, 2],
11471148
];
@@ -1175,7 +1176,7 @@ public function testHasManySelectableRelationshipWithForceDelete()
11751176
$inputData = [
11761177
'name' => $faker->name,
11771178
'email' => $faker->safeEmail,
1178-
'password' => bcrypt($faker->password()),
1179+
'password' => Hash::make($faker->password()),
11791180
'remember_token' => null,
11801181
'planets' => [1, 2],
11811182
];
@@ -1208,7 +1209,7 @@ public function testHasManySelectableRelationshipNonNullableForeignKeyAndDefault
12081209
$inputData = [
12091210
'name' => $faker->name,
12101211
'email' => $faker->safeEmail,
1211-
'password' => bcrypt($faker->password()),
1212+
'password' => Hash::make($faker->password()),
12121213
'remember_token' => null,
12131214
'comets' => [1, 2],
12141215
];
@@ -1242,7 +1243,7 @@ public function testHasManySelectableRelationshipNonNullable()
12421243
$inputData = [
12431244
'name' => $faker->name,
12441245
'email' => $faker->safeEmail,
1245-
'password' => bcrypt($faker->password()),
1246+
'password' => Hash::make($faker->password()),
12461247
'remember_token' => null,
12471248
'planetsNonNullable' => [1, 2],
12481249
];
@@ -1282,7 +1283,7 @@ public function testCreateHasManyRelationWithDelimitedNameSubfields()
12821283
$inputData = [
12831284
'name' => $faker->name,
12841285
'email' => $faker->safeEmail,
1285-
'password' => bcrypt($faker->password()),
1286+
'password' => Hash::make($faker->password()),
12861287
'remember_token' => null,
12871288
'universes' => [
12881289
[
@@ -1335,7 +1336,7 @@ public function testCreateHasOneRelationWithDelimitedNameSubfields()
13351336
$inputData = [
13361337
'name' => $faker->name,
13371338
'email' => $faker->safeEmail,
1338-
'password' => bcrypt($faker->password()),
1339+
'password' => Hash::make($faker->password()),
13391340
'remember_token' => null,
13401341
'roles' => [1, 2],
13411342
'accountDetails' => [
@@ -1383,7 +1384,7 @@ public function testBelongsToManyWithDelimitedNameSubfields()
13831384
$inputData = [
13841385
'name' => $faker->name,
13851386
'email' => $faker->safeEmail,
1386-
'password' => bcrypt($faker->password()),
1387+
'password' => Hash::make($faker->password()),
13871388
'remember_token' => null,
13881389
'superArticles' => [
13891390
[

tests/Unit/CrudPanel/CrudPanelUpdateTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Faker\Factory;
77
use Illuminate\Database\Eloquent\ModelNotFoundException;
88
use Illuminate\Support\Facades\DB;
9+
use Illuminate\Support\Facades\Hash;
910

1011
/**
1112
* @covers Backpack\CRUD\app\Library\CrudPanel\Traits\Update
@@ -65,7 +66,7 @@ public function testUpdate()
6566
$inputData = [
6667
'name' => $faker->name,
6768
'email' => $faker->safeEmail,
68-
'password' => bcrypt($faker->password()),
69+
'password' => Hash::make($faker->password()),
6970
];
7071

7172
$entry = $this->crudPanel->update(1, $inputData);
@@ -84,7 +85,7 @@ public function testUpdateUnknownId()
8485
$inputData = [
8586
'name' => $faker->name,
8687
'email' => $faker->safeEmail,
87-
'password' => bcrypt($faker->password()),
88+
'password' => Hash::make($faker->password()),
8889
];
8990

9091
$unknownId = DB::getPdo()->lastInsertId() + 2;
@@ -99,7 +100,7 @@ public function testGetUpdateFields()
99100
$inputData = [
100101
'name' => $faker->name,
101102
'email' => $faker->safeEmail,
102-
'password' => bcrypt($faker->password()),
103+
'password' => Hash::make($faker->password()),
103104
];
104105
$entry = $this->crudPanel->create($inputData);
105106
$this->addValuesToExpectedFields($entry->id, $inputData);

tests/config/database/seeds/UsersTableSeeder.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Database\Seeder;
66
use Illuminate\Support\Facades\DB;
7+
use Illuminate\Support\Facades\Hash;
78
use Illuminate\Support\Str;
89

910
class UsersTableSeeder extends Seeder
@@ -22,7 +23,7 @@ public function run()
2223
'id' => 1,
2324
'name' => $faker->name,
2425
'email' => $faker->unique()->safeEmail,
25-
'password' => bcrypt('secret'),
26+
'password' => Hash::make('secret'),
2627
'remember_token' => Str::random(10),
2728
'created_at' => $now,
2829
'updated_at' => $now,
@@ -32,7 +33,7 @@ public function run()
3233
'id' => 2,
3334
'name' => $faker->name,
3435
'email' => $faker->unique()->safeEmail,
35-
'password' => bcrypt('secret'),
36+
'password' => Hash::make('secret'),
3637
'remember_token' => Str::random(10),
3738
'created_at' => $now,
3839
'updated_at' => $now,

0 commit comments

Comments
 (0)