Skip to content

[ShanaBoo] [ Laravel ] Fix User model password cast not applying bcrypt rounds from config#4419

Closed
genesisrevelationinc-debug wants to merge 6 commits into
UnsafeLabs:mainfrom
genesisrevelationinc-debug:shanaboo-fix-745
Closed

[ShanaBoo] [ Laravel ] Fix User model password cast not applying bcrypt rounds from config#4419
genesisrevelationinc-debug wants to merge 6 commits into
UnsafeLabs:mainfrom
genesisrevelationinc-debug:shanaboo-fix-745

Conversation

@genesisrevelationinc-debug
Copy link
Copy Markdown

ShanaBoo Autonomous Fix

This PR was automatically generated by ShanaBoo Earn Engine to claim the $50.00 bounty on this issue.

Source: Github | Task: 4451685810

Closes #745


Auto-submitted by ShanaBoo CNS — NVIDIA NIM + Microsoft Agent Framework

Copilot AI review requested due to automatic review settings May 25, 2026 07:07
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds explicit bcrypt “rounds” handling and coverage around password hashing behavior.

Changes:

  • Added unit tests asserting password hashes use the configured bcrypt cost.
  • Updated UserFactory to pass configured bcrypt rounds into Hash::make.
  • Added a User::setPasswordAttribute mutator to always hash passwords with configured rounds.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
laravel/tests/Unit/UserPasswordHashingTest.php Adds unit tests for bcrypt rounds/cost behavior.
laravel/database/factories/UserFactory.php Attempts to ensure factory-created users hash passwords with configured rounds.
laravel/app/Models/User.php Introduces a password mutator that forces hashing with configured bcrypt rounds.
Comments suppressed due to low confidence (1)

laravel/app/Models/User.php:1

  • Adding setPasswordAttribute() here conflicts with the existing 'password' => 'hashed' cast and can cause double-hashing. For example, if code (or the factory) passes an already-hashed password into the model, this mutator will hash the hash again, breaking authentication. Prefer relying on the built-in hashed cast (it is designed to avoid re-hashing when appropriate), or make the mutator conditional (e.g., only hash when the incoming value is not already hashed). Additionally, forcing ['rounds' => config('hashing.bcrypt.rounds')] bakes in bcrypt-specific options even if the app’s hashing driver is argon/argon2id.
<?php

Comment on lines +17 to +36
$rounds = config('hashing.bcrypt.rounds');
$password = 'secret';
$hashedPassword = Hash::make($password, ['rounds' => $rounds]);

$this->assertEquals($rounds, 10);
$this->assertTrue(Hash::check($password, $hashedPassword));
}

public function test_user_password_hashing_respects_config()
{
// This assumes there's a User model instance to test against
// We'll create a user and check if the password was hashed with the right cost
$user = User::factory()->make([
'password' => 'password'
]);

$hash = $user->password;
$expectedRounds = config('hashing.bcrypt.rounds');
$info = password_get_info($hash);

Comment on lines +33 to +38
$hash = $user->password;
$expectedRounds = config('hashing.bcrypt.rounds');
$info = password_get_info($hash);

$this->assertArrayHasKey('cost', $info);
$this->assertEquals($expectedRounds, $info['cost']);
Comment thread laravel/app/Models/User.php Outdated
Comment on lines +40 to +45
public function setPasswordAttribute($value): void
{
$this->attributes['password'] = Hash::make($value, [
'rounds' => config('hashing.bcrypt.rounds')
]);
}
Comment on lines 29 to 35
'name' => fake()->name(),
'email' => fake()->unique()->safeEmail(),
'email_verified_at' => now(),
'password' => static::$password ??= Hash::make('password'),
'password' => static::$password ??= Hash::make('password', [
'rounds' => config('hashing.bcrypt.rounds')
]),
'remember_token' => Str::random(10),
Comment on lines +7 to +13
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
use Illuminate\Support\Facades\Hash;

class UserPasswordHashingTest extends TestCase
{
use RefreshDatabase, WithFaker;
@github-actions
Copy link
Copy Markdown
Contributor

Unfortunately the changes in this PR didn't fully resolve the issue. Please rework your solution and submit a new pull request.

Make sure to review the acceptance criteria in the linked issue and verify all conditions are met before resubmitting. See CONTRIBUTING.md for guidelines.

@github-actions github-actions Bot closed this May 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ Laravel ] Fix User model password cast not applying bcrypt rounds from config

2 participants