Created
August 22, 2018 15:31
-
-
Save Artistan/7bcf07107ce58067f3434a71e75a2fdd to your computer and use it in GitHub Desktop.
Laravel 5.6 Password does/not contain login name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App; | |
use Illuminate\Support\Facades\Input; | |
use Illuminate\Validation\Validator; | |
/** | |
* Class Extend | |
*/ | |
class Extend | |
{ | |
/** | |
* @example | |
* Validator::extend('not_contains', 'App\Extend@not_contains'); | |
* | |
* -- add rule to attribute validation, | |
* -- in this case it checks if the 'login' Input is NOT in the password value | |
* 'password' => [ ... | |
* 'not_contains:login', | |
* ] | |
* /example | |
* @param string $attribute | |
* @param mixed $value | |
* @param mixed $parameters | |
* @param Validator $validator | |
* @return bool | |
*/ | |
public function not_contains($attribute, $value, $parameters, Validator $validator) | |
{ | |
if(self::require_parameters($parameters,1) && $attribute_value = Input::get($parameters[0])){ | |
return strpos(strtoupper($value), strtoupper($attribute_value))===false?true:false; | |
} | |
return false; | |
} | |
/** | |
* @example | |
* Validator::extend('contains', 'App\Extend@contains'); | |
* | |
* -- add rule to attribute validation, | |
* -- in this case it checks if the 'login' Input is in the password value | |
* 'password' => [ ... | |
* 'contains:login', | |
* ] | |
* /example | |
* @param string $attribute | |
* @param mixed $value | |
* @param mixed $parameters | |
* @param Validator $validator | |
* @return bool | |
*/ | |
public function contains($attribute, $value, $parameters, Validator $validator) | |
{ | |
if(self::require_parameters($parameters,1) && $attribute_value = Input::get($parameters[0])){ | |
return strpos(strtoupper($value), strtoupper($attribute_value))===false?false:true; | |
} | |
return false; | |
} | |
private static function require_parameters($parameters,$count) { | |
return count($parameters) === $count; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment