File path:
/vendor/magento/module-customer/Model/Customer/Attribute/Backend/Password.php
const MIN_PASSWORD_LENGTH = 6;
You can set your min password length value here.
For create your own custom file :
/app/code/VendorName/ModuleName/Model/Customer/Attribute/Backend/Password.php
Add this below code in file :
<?php
namespace VendorName\ModuleName\Model\Customer\Attribute\Backend;
use Magento\Framework\Exception\LocalizedException;
class Password extends \Magento\Customer\Model\Customer\Attribute\Backend\Password
{
/**
* Min password length
*/
const MIN_PASSWORD_LENGTH = 5; // set your custom length of min password
/**
* Magento string lib
*
* @var \Magento\Framework\Stdlib\StringUtils
*/
protected $string;
/**
* @param \Magento\Framework\Stdlib\StringUtils $string
*/
public function __construct(\Magento\Framework\Stdlib\StringUtils $string)
{
$this->string = $string;
}
/**
* check some rule for password & transform temporary attribute 'password' into real attribute 'password_hash' process.
*
*/
public function beforeSave($object)
{
$password = $object->getPassword();
$length = $this->string->strlen($password);
if ($length > 0) {
if ($length < self::MIN_PASSWORD_LENGTH) {
throw new LocalizedException(
__('Please enter a password with at least %1 characters.', self::MIN_PASSWORD_LENGTH)
);
}
if (trim($password) !== $password) {
throw new LocalizedException(__('The password can not begin or end with a space.'));
}
$object->setPasswordHash($object->hashPassword($password));
}
}
/**
* @param \Magento\Framework\DataObject $object
* @return bool
*/
public function validate($object)
{
$password = $object->getPassword();
if ($password && $password === $object->getPasswordConfirm()) {
return true;
}
return parent::validate($object);
}
}
Hope, It will helpful for you.
If issue solved,Click Kudos & Accept as Solution