From 439d86cc5220b692d71313016d6cb84e920fc390 Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Sun, 9 Oct 2016 15:49:19 +0100 Subject: [PATCH] Use a custom facade rather than overwriting Laravel's hasher --- src/Facades/WPHash.php | 23 +++++++++++++++++++++++ src/Hashing/HashServiceProvider.php | 9 +++++---- src/Hashing/WordpressHasher.php | 6 ++---- src/Providers/KoseligServiceProvider.php | 4 ++++ 4 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 src/Facades/WPHash.php diff --git a/src/Facades/WPHash.php b/src/Facades/WPHash.php new file mode 100644 index 0000000..80ab20d --- /dev/null +++ b/src/Facades/WPHash.php @@ -0,0 +1,23 @@ + + */ +class WPHash extends Facade +{ + /** + * Get the registered name of the component. + * + * @return string + */ + protected static function getFacadeAccessor() + { + return 'wphash'; + } +} diff --git a/src/Hashing/HashServiceProvider.php b/src/Hashing/HashServiceProvider.php index 3619c1d..5ff0565 100644 --- a/src/Hashing/HashServiceProvider.php +++ b/src/Hashing/HashServiceProvider.php @@ -4,7 +4,8 @@ namespace Koselig\Hashing; use Illuminate\Support\ServiceProvider; /** - * Replace Laravel's hasher with Wordpress'. + * Provide 'wphash' service to allow for hashing using Wordpress' + * hashing methods. * * @author Jordan Doyle */ @@ -24,8 +25,8 @@ class HashServiceProvider extends ServiceProvider */ public function register() { - $this->app->singleton('hash', function () { - return new WordpressHasher; + $this->app->singleton('wphash', function () { + return new WordpressHasher(); }); } @@ -36,6 +37,6 @@ class HashServiceProvider extends ServiceProvider */ public function provides() { - return ['hash']; + return ['wphash']; } } diff --git a/src/Hashing/WordpressHasher.php b/src/Hashing/WordpressHasher.php index 4a35120..250e70d 100644 --- a/src/Hashing/WordpressHasher.php +++ b/src/Hashing/WordpressHasher.php @@ -22,8 +22,6 @@ class WordpressHasher implements HasherContract */ public function make($value, array $options = []) { - dd(wp_hash_password($value)); - return wp_hash_password($value); } @@ -49,7 +47,7 @@ class WordpressHasher implements HasherContract */ public function needsRehash($hashedValue, array $options = []) { - return false; + // if the hashed value is md5 it needs rehashing. + return strlen($hashedValue) <= 32; } } - diff --git a/src/Providers/KoseligServiceProvider.php b/src/Providers/KoseligServiceProvider.php index 6136645..9a518e7 100644 --- a/src/Providers/KoseligServiceProvider.php +++ b/src/Providers/KoseligServiceProvider.php @@ -3,6 +3,7 @@ namespace Koselig\Providers; use Illuminate\Support\ServiceProvider; use Koselig\Auth\AuthServiceProvider; +use Koselig\Hashing\HashServiceProvider; use Koselig\Routing\RoutingServiceProvider; /** @@ -28,5 +29,8 @@ class KoseligServiceProvider extends ServiceProvider // Authentication service provider $this->app->register(AuthServiceProvider::class); + + // Hashing service provider + $this->app->register(HashServiceProvider::class); } } -- libgit2 1.7.2