Jump to content

How to change requirements of customer password


AndersHelbo

Recommended Posts

Hi

 

I am running Prestashop v. 1.5.6.2 on a webshop.

 

Regarding to the password that the customer chooses when register on the webshop, I want to change the requirements for that.

 

I already made it, so it has to be at least six characters long. Besides that, I want to change the requirements of the content in the password.

 

it has to contain min. one capital letter. Is there a way to change this requirements in the files somewhere? I have looked under .../classes/validation.php but could not change anything else but the number of the characters?

 

Does someone know how to do this?

  • Like 1
Link to comment
Share on other sites

you can achieve it with regular expression:

/^([a-z])([A-Z])([\d,.;:])/

(?=.*[a-z]) checks if somewhere in the string is a lowercase character

(?=.*[A-Z]) checks if somewhere in the string is a uppercase character

(?=.*[\d,.;:]) checks if somewhere in the string is a digit or one of the other characters, add those you want.

 
do you know how to apply it to Validate controller or you need an detailed explanation? :)
Link to comment
Share on other sites

 

you can achieve it with regular expression:

/^([a-z])([A-Z])([\d,.;:]).+$/

(?=.*[a-z]) checks if somewhere in the string is a lowercase character

(?=.*[A-Z]) checks if somewhere in the string is a uppercase character

(?=.*[\d,.;:]) checks if somewhere in the string is a digit or one of the other characters, add those you want.

 
do you know how to apply it to Validate controller or you need an detailed explanation? :)

 

Thanks. It would be great with some kind of guide, how to implement this into the file.

And what about old accounts with passwords which are not validated in the new way? Will they still be able to login with their old passwords?

Link to comment
Share on other sites

no, they will not be able to log in with old password :(

but you can remove this:

		elseif (!Validate::isPasswd($passwd))
			$this->errors[] = Tools::displayError('Invalid password.');

from processSubmitLogin() function in controllers/front/AuthController.php

 

give me 5 minutes im going to prepare code :-)

Link to comment
Share on other sites

  /**
	 * Check for password validity for capitals
	 *
	 * @param string $passwd Password to validate
	 * @return boolean Validity is ok or not
     * @author VEKIA :-) http://MyPresta.eu
	 */ 
    public static function isPasswdPro($passwd){
        if (preg_match('/[A-Z]/',$passwd)){
            return true;
        } else {
            return false;
        }
    } 
    
    /**
	 * Check for password validity
	 *
	 * @param string $passwd Password to validate
	 * @param int $size
	 * @return boolean Validity is ok or not
	 */
	public static function isPasswd($passwd, $size = Validate::PASSWORD_LENGTH){
	    if ((Tools::strlen($passwd) >= $size && Tools::strlen($passwd) < 255) && Validate::isPasswdPro($passwd)){
		  return true;
        } else {
          return false;
        }
	}

i modified main isPasswd function - added there if condition to check if isPasswdPro returns true.

in this case this function checks Capitals in password

  • Like 2
Link to comment
Share on other sites

  • 2 weeks later...

Hello

Just picked this topic up from a topic posted today.

 

What code would I need if I wanted a customers password to be:

Minimum 8 charactors

Contain at least 1 lowercase letter

Contain at least 1 uppercase letter

Contain at least 1 symbol (+×#@!/%&€£*,:;) etc

 

Also, what type of password would a customer get if they click the "forgot your password" link

 

This could be a great tutorial

 

Paul

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 months later...

Well I got a different situation.

 

I want to validate the password field for upper case, lower case, number and special character so I have configured my validate.php. 

The customer part is working good. But the Admin doesn't load and shows an array when I activate the developer mode.

 

case 1:

I investigated and found that isPasswdAdmin() also calls the isPasswd () and my admin password doesn't satisfy that condition. So I renamed the isPasswd() inside  isPasswdAdmin() and added a new method with the older isPasswd() content. That didn't work. Again case2:

Changed my admin password to satisfy the isPasswd() but still that doesn't work. 

 

Any solution guys ? 

 

I couldn't post the lines due to special characters. SO I'm attaching a file with my code.

Validate.php

Edited by J.Sahu (see edit history)
Link to comment
Share on other sites

  • 11 months later...

if you want more stuff, like special chars, numbers etc. just let me know :D i love topics like that :D

 

Hi Vekia,

 

Thank you so much for your help. I have got the error in 1.6 after changing when I validate everything and it redirect another page and it said 

500 Server Error

Oops, something went wrong.

 

Try to refresh this page or feel free to contact us if the problem persists.

 

 

Please Help me.

 

THanks

Link to comment
Share on other sites

  • 4 months later...

Hi,

 

is it any sollution for "500"?

 

Your code, vekia, seems to be correct, error appears only when conditions are fulfilled.

 

I have got:
 

[PrestaShopException]

Property Customer->passwd is not valid
at line 909 in file classes/ObjectModel.php

904.             }905. 906.             $message = $this->validateField($field, $this->$field);907.             if ($message !== true) {908.                 if ($die) {909.                     throw new PrestaShopException($message);910.                 }911.                 return $error_return ? $message : false;912.             }913.         }914. 

[PrestaShop 1.6.1.4]

 

Can anyone help?

 

Thanks in advance.

Link to comment
Share on other sites

  • 2 years later...
On 9/25/2014 at 7:39 AM, vekia said:

  /**
	 * Check for password validity for capitals
	 *
	 * @param string $passwd Password to validate
	 * @return boolean Validity is ok or not
     * @author VEKIA :-) http://MyPresta.eu
	 */ 
    public static function isPasswdPro($passwd){
        if (preg_match('/[A-Z]/',$passwd)){
            return true;
        } else {
            return false;
        }
    } 
    
    /**
	 * Check for password validity
	 *
	 * @param string $passwd Password to validate
	 * @param int $size
	 * @return boolean Validity is ok or not
	 */
	public static function isPasswd($passwd, $size = Validate::PASSWORD_LENGTH){
	    if ((Tools::strlen($passwd) >= $size && Tools::strlen($passwd) < 255) && Validate::isPasswdPro($passwd)){
		  return true;
        } else {
          return false;
        }
	}

i modified main isPasswd function - added there if condition to check if isPasswdPro returns true.

in this case this function checks Capitals in password

I can see that option is for login, but not for register.

Im looking for a solution for check strong passwords on register form.

 

 

 

Link to comment
Share on other sites

  • 1 year later...
  • 11 months later...
4 uren geleden, depthworld zei:

Good information I also go through the same problem hope it's help out. [email protected]

 

Please post a new post about this with all the required information, you're responding to a post from 7 years ago, prestashop has changed multiple times since then. Share your PS version etc. and post a new post.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...