2019-05-09 06:54:39 +00:00
|
|
|
<?php
|
|
|
|
|
|
2020-03-24 17:56:32 +00:00
|
|
|
namespace Appwrite\Auth\Validator;
|
2019-05-09 06:54:39 +00:00
|
|
|
|
|
|
|
|
use Utopia\Validator;
|
|
|
|
|
|
|
|
|
|
/**
|
2019-09-06 17:04:26 +00:00
|
|
|
* Password.
|
2019-05-09 06:54:39 +00:00
|
|
|
*
|
|
|
|
|
* Validates user password string
|
|
|
|
|
*/
|
|
|
|
|
class Password extends Validator
|
|
|
|
|
{
|
|
|
|
|
/**
|
2019-09-06 17:04:26 +00:00
|
|
|
* Get Description.
|
2019-05-09 06:54:39 +00:00
|
|
|
*
|
|
|
|
|
* Returns validator description
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2021-12-13 15:42:40 +00:00
|
|
|
public function getDescription(): string
|
2019-05-09 06:54:39 +00:00
|
|
|
{
|
2021-11-25 20:07:54 +00:00
|
|
|
return 'Password must be at least 8 characters';
|
2019-05-09 06:54:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-09-06 17:04:26 +00:00
|
|
|
* Is valid.
|
2019-05-09 06:54:39 +00:00
|
|
|
*
|
2019-09-06 17:04:26 +00:00
|
|
|
* @param mixed $value
|
|
|
|
|
*
|
2019-05-09 06:54:39 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
2021-12-13 15:42:40 +00:00
|
|
|
public function isValid($value): bool
|
2019-05-09 06:54:39 +00:00
|
|
|
{
|
2021-11-25 20:07:54 +00:00
|
|
|
if (!\is_string($value)) {
|
|
|
|
|
return false;
|
2022-05-23 14:54:50 +00:00
|
|
|
}
|
2021-11-25 20:07:54 +00:00
|
|
|
|
|
|
|
|
if (\strlen($value) < 8) {
|
2019-05-09 06:54:39 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2021-04-13 08:46:30 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Is array
|
|
|
|
|
*
|
|
|
|
|
* Function will return true if object is array.
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function isArray(): bool
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get Type
|
|
|
|
|
*
|
|
|
|
|
* Returns validator type.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getType(): string
|
|
|
|
|
{
|
|
|
|
|
return self::TYPE_STRING;
|
|
|
|
|
}
|
2019-09-06 17:04:26 +00:00
|
|
|
}
|