One other alternative is to set a mutator on your user model.
class User extends Eloquent {
public function setPasswordAttribute($password) {
$this->attributes['password'] = Hash::make($password);
}
}
In this way, you can be sure that the password will be hashed every time you set the attribute in the user model, which will also help you cut down on duplicated code.
@rosshulford@deringer Above suggestion (with mutator) is definitely the best way to handle this. Apart from it being convenient, it also makes sure you never save a user with plain password attribute (unless you do, for it's still possible if you want ofc)
I found the following function within the Illuminate\Auth\Authenticatable interface and the Illuminate\Auth\GenericUser class that implements Authenticatable as UserContract. There is a getAuthPassword() method.
Would be useful for the same functionality comparing with the Hash::make() function?
Edit. I think it would not possible for the Hashing process because it use the date and time, correct me if I'm wrong...
What do you think about the following approach: instead of having the HasherContract return a hashed string, we can transform it into a value object HashedValue which implements the __toString() method, such that you can determine if a string has been hashed or not.