I edited the app/code/core/Mage/Customer/Model/Customer/Attribute/Backend/Password.php file and removed the requirement completely but the cart still requires a six character password. I want to knock it down to only five. Is there another file aside from this one that I need to edit?
The customer login form on the my account section also uses javascript to validate form input. In js/prototyp/validation.js, on line 370 (search for the string ‘validate-password’). Change both of the 6’s to whatever limit you want.
['validate-password', 'Please enter 6 or more characters. Leading or trailing spaces will be ignored.', function(v) { var pass=v.strip(); /*strip leading and trailing spaces*/ return !(pass.length>0 && pass.length < 6);
Thanks for pointing out the code to change. I needed to drop the password requirement to 5 characters also on my site.
Out of curiosity, there is another snippet of code in validation.js that mentions 6 characters.
['validate-new-password', 'Please enter 6 or more characters. Leading or trailing spaces will be ignored.', function(v) { if (!Validation.get('validate-password').test(v)) return false; if (Validation.get('IsEmpty').test(v) && v != '') return false; return true; }],
I couldn’t tell what it affected, so I just changed to it to say “5 or more characters”.
I assume that the modification in both files will be overwritten during an upgrade via MagentoConnect.
The modifications done on validation.js will be gone when Magento is updated with new versions. Is there a way to do a js update like the template or skin update?
Check out the author of validation.js here http://tetlaw.id.au/view/javascript/really-easy-field-validation. It is possible to add custom validation to the js thereby creating a kind of js update without worry about the rewrite by Magento update. For example: in the phtml file, specify the custom class in the input field, in my case validate-awb:
I want the input text to be within 9 to 12 digits, the js code inserted within the same phtml file is
<script type="text/javascript"> //<![CDATA[ var trackForm = new VarienForm('track-awb'); Validation.add('validate-awb', 'Please use 9 to 12 numbers only in this field.', { minLength : 9, maxLength : 12, include : ['validate-digits'] }); //]]> </script>
Note, I included the in-built function validate-digits to validate for numbers.
So far so good. But I need to be able to return a backend validation message/advise, and I do not know enough js and AJAX to do it. Can anyone throw some light? Thanks.
I have just been struggling along with the similar problem and got it working after following advice in this thread.
A lot of the validation code seems fairly spread out between files. For anyone interested, the JavaScript change is necessary to prevent validation failing before postback, the other validation is done later, server-side.
Anyway, after following the instructions above, I still couldn’t save a shorter password until I edited the following class:
There is a method in there called beforeSave() that also checks the length of the password. Setting this to my new desired length did the trick for me. Hope this helps!
if ($password && !Zend_Validate::is($password, \'StringLength\', array(6))) { $errors[] = Mage::helper(\'customer\')->__(\'Password minimal length must be more %s\', 6); }
if ($password && !Zend_Validate::is($password, 'StringLength', array(6))) { $errors[] = Mage::helper('customer')->__('Password minimal length must be more %s', 6); }
if ($password && !Zend_Validate::is($password, \'StringLength\', array(6))) { $errors[] = Mage::helper(\'customer\')->__(\'Password minimal length must be more %s\', 6); }