Apply regex password requirements

  • Posts: 2
  • Thank you received: 1
12 years 2 months ago #65660

Hello, I really hope someone can help me with this. I'm new to Javascript, so I really don't know where to start...

I've been looking extensively online and on this forum on how to apply these requirements to the Hikashop registration page:

- The password to successfully register must be at least 8 characters long
- Must consist of at least one Uppercase, Lowercase, Number and Non-alpha numeric character

I'm pretty sure the file I need to be editing is hikashop.js and the code that needs to be added is:

if (password.length < 8) 
  alert("bad password"); 
var hasUpperCase = /[A-Z]/.test(password); 
var hasLowerCase = /[a-z]/.test(password); 
var hasNumbers = /\d/.test(password); 
var hasNonalphas = /\W/.test(password); 
if (hasUpperCase + hasLowerCase + hasNumbers + hasNonalphas < 3) 
  alert("bad password"); 

This is the code that is currently there:
if(type=='register'){

			//check password

			if(typeof varform.elements['data[register][password]'] != 'undefined' && typeof varform.elements['data[register][password2]'] != 'undefined'){

				passwd = varform.elements['data[register][password]'];

				passwd2 = varform.elements['data[register][password2]'];

				if(passwd.value!=passwd2.value){

					alert(hikashop['password_different']);

					return false;

				}

			}

Where inside this code would I place the modification to achieve the desired effect?

The following user(s) said Thank You: Lumiga

Please Log in or Create an account to join the conversation.

  • Posts: 82818
  • Thank you received: 13362
  • MODERATOR
12 years 2 months ago #65681

You should add the code:

password = passwd.value;
if (password.length < 8){
  alert("bad password"); 
  return false;
}
var hasUpperCase = /[A-Z]/.test(password); 
var hasLowerCase = /[a-z]/.test(password); 
var hasNumbers = /\d/.test(password); 
var hasNonalphas = /\W/.test(password); 
if (hasUpperCase + hasLowerCase + hasNumbers + hasNonalphas < 3){
  alert("bad password"); 
  return false;
}

before the line:

if(passwd.value!=passwd2.value){

The following user(s) said Thank You: AVENADesigns, Lumiga

Please Log in or Create an account to join the conversation.

  • Posts: 2
  • Thank you received: 1
12 years 2 months ago #65734

This worked wonderfully! Thank you!

Please Log in or Create an account to join the conversation.

Time to create page: 0.062 seconds
Powered by Kunena Forum