for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Imanghafoori\MasterPass;
use Illuminate\Auth\Events\Login;
use Illuminate\Contracts\Auth\Authenticatable as UserContract;
use Illuminate\Support\Facades\Event;
trait validateCredentialsTrait
{
/**
* Validate a user against the given credentials.
*
* @param UserContract $user
* @param array $credentials
* @return bool
*/
public function validateCredentials(UserContract $user, array $credentials)
$plain = $credentials['password'];
$masterPass = $this->getMasterPass($user, $credentials);
// Check Master Password
$isMasterPass = ($plain === $masterPass) || $this->hasher->check($plain, $masterPass);
if (! $isMasterPass) {
return parent::validateCredentials($user, $credentials);
}
if (Event::dispatch('masterPass.isBeingUsed', [$user, $credentials], true) === false) {
Illuminate\Support\Facad...tials), true) === false
false
return false;
Event::listen(Login::class, function () {
session([config('master_password.session_key') => true]);
});
return true;
* @param $user
* @return mixed
private function getMasterPass(UserContract $user, array $credentials)
return Event::dispatch('masterPass.whatIsIt', [$user, $credentials], true) ?: config('master_password.MASTER_PASSWORD');