I am porting an outdated application to Laravel. The old application used MD5 to hash passwords without salt, so I need to repeat this in Laravel. For recording, we change the passwords to bcrypt with salt, but this is not a simple process, and this requires a user login - for now I just need to get logins that work with outdated hashes.
I followed this guide to convert Auth::hash to MD5: How to use SHA1 encryption instead of BCrypt in Laravel 4?
When I register a password in plain text and a generated hash in my make method when registering an account:
public function make($value, array $options = array()) { echo $value.'<br>'.hash('md5', $value); exit; return hash('md5', $value); }
I get the following:
123456 e10adc3949ba59abbe56e057f20f883e
Great for what I need. However, when this is stored in the database, I get a completely different hash. I assume Laravel is poking the password elsewhere, but I cannot find where and how to override this.
My MD5Hasher.php file inside app/libraries :
<?php class MD5Hasher implements Illuminate\Contracts\Hashing\Hasher { public function make($value, array $options = array()) { return hash('md5', $value); } public function check($value, $hashedValue, array $options = array()) { return $this->make($value) === $hashedValue; } public function needsRehash($hashedValue, array $options = array()) { return false; } }
My MD5HashServiceProvider.php :
<?php class MD5HashServiceProvider extends Illuminate\Support\ServiceProvider { public function register() { $this->app['hash'] = $this->app->share(function () { return new MD5Hasher(); }); } public function provides() { return array('hash'); } }
My AuthController.php as follows:
<?php namespace App\Http\Controllers\Auth; use Hash; use App\User; use Validator; use Mail; use App\Http\Controllers\Controller; use Illuminate\Foundation\Auth\ThrottlesLogins; use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers; class AuthController extends Controller { use AuthenticatesAndRegistersUsers, ThrottlesLogins;