如何改进OpenCart的这个密码验证?

问题描述 投票:-1回答:1

以下是github上Opencart 2.3.0.2的默认代码。它存在于大约5个php文件中。目前的密码要求是最少4个字符,最多20个字符。我想把它变成8个最小字符,一个大写,一个小写,还有一个特殊字符。它必须是类似的格式,以便我可以粘贴在代码上。

https:/github.comopencartopencartblob2.2.0.0uploadcatalogcontrolleraccountpassword.php。

        if ((utf8_strlen($this->request->post['password']) < 4) || (utf8_strlen($this->request->post['password']) > 20)) {
            $this->error['password'] = $this->language->get('error_password');

这个能不能用,还是有更好的?


        if (!preg_match('^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&amp;+=])(?=\S+$).{8,}$', $this->request->post['password'])) {
            $this->error['password'] = $this->language->get('error_password');
php passwords preg-match opencart opencart2.x
1个回答
0
投票

你可以试试这个...

if (!preg_match('/(?=^.{8,40}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$/', html_entity_decode($this->request->post['password'], ENT_QUOTES, 'UTF-8'))) {

最少8个字符,最多40个字符,一个大写字母和一个小写字母。如果你想检查特殊字符,你应该添加额外的gex。

© www.soinside.com 2019 - 2024. All rights reserved.