From b005cc4dd752fd88f53d2a2c61c1e96289bde56e Mon Sep 17 00:00:00 2001 From: Moamen Eltouny <16774083+MoamenEltouny@users.noreply.github.com> Date: Tue, 13 Dec 2022 13:05:56 +0200 Subject: [PATCH] Validate password before hash it --- src/Traits/Password/HasHashedPassword.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Traits/Password/HasHashedPassword.php b/src/Traits/Password/HasHashedPassword.php index 6e5187b..f756efe 100644 --- a/src/Traits/Password/HasHashedPassword.php +++ b/src/Traits/Password/HasHashedPassword.php @@ -19,11 +19,12 @@ trait HasHashedPassword public static function bootHasHashedPassword() { self::creating(function ($model) { - $model->password = Hash::make($model->password); + if (!empty($model->password)) + $model->password = Hash::make($model->password); }); self::updating(function ($model) { - if ($model->isDirty('password')) { + if ($model->isDirty('password') && !empty($model->password)) { $model->password = Hash::make($model->password); } });