Laravel uses Bcrypt to securely hash passwords, meaning you can’t just type a new plain-text password directly into the database. It must be hashed using Laravel’s built-in functions. Follow these steps to correctly reset a user’s password from the terminal.
Step 1: Log in to cPanel
Access your cPanel account through your hosting provider.
Step 2: Open the Terminal
- In cPanel, scroll down to the Advanced section.
- Click on Terminal to launch the command line interface.
Step 3: Navigate to Your Laravel Project
Use the following command to go to the Laravel directory:
cd public_html
Modify the path if your Laravel project is in a different directory.
Step 4: Launch Laravel Tinker
Enter the following command:
php artisan tinker
You should now see a console prompt that looks like this:
>>>
Step 5: Generate the Hashed Password
At the Tinker prompt, type the command below:
echo Hash::make('your-new-password');
Replace your-new-password with the password you want to use.
Example:
echo Hash::make('MySecurePass123');
You’ll get an output like this:
$2y$10$GTP5DRX5IBTH9iCikZV7zeKHZeRC9EHP28Hs2LaHBGC9oZkTaHKfW
Copy this hashed password — you’ll need it for the next step.
Step 6: Update the Password in the Database
- Open phpMyAdmin from cPanel.
- Select your Laravel project’s database.
- Click on the users table.
- Find the user you want to update.
- Paste the hashed password into the password field.
- Click Save or Go to apply the changes.
Step 7: Test the New Password
You can now log in to your Laravel app with the user’s email or username and the new password.
Important Tips
- Never insert plain-text passwords into the database.
- Always use Laravel’s hashing to maintain security.
- This method is suitable for both development and production environments.