-1

Below is the default code from Opencart 2.3.0.2 on github. Its found in approx 5 php files. Currently the password requirements is min 4 and max 20 characters. I want to make it 8 min, one uppercase, one lowercase, and a special character. It has to be similar format so that i can paste over the code.

https://github.com/opencart/opencart/blob/2.2.0.0/upload/catalog/controller/account/password.php

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

Could this work or is there a better one?


        if (!preg_match('^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&amp;+=])(?=\S+$).{8,}$', $this->request->post['password'])) {
            $this->error['password'] = $this->language->get('error_password');

1 Answers1

0

You can try this...

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

This for 8 min. and 40 max. characters, one uppercase and one lowercase letter. If you wish to check special character, you should add additional regex.

K. B.
  • 1,388
  • 2
  • 13
  • 25