Skip to content

Instantly share code, notes, and snippets.

@Artistan
Created August 22, 2018 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Artistan/7bcf07107ce58067f3434a71e75a2fdd to your computer and use it in GitHub Desktop.
Save Artistan/7bcf07107ce58067f3434a71e75a2fdd to your computer and use it in GitHub Desktop.
Laravel 5.6 Password does/not contain login name
<?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