1

I have a piece of code that I've been told to change from the upper management, it's a password secure algorithm that only allows password which contains certain characters and numbers in javascript. Right now it allows only passwords which

  • Contains at least one lowercase.
  • Contains at least one uppercase.
  • Contains at least one number.
  • Contains at least 6 characters.

The code itself, is displayed here:

var re = /(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,}/;

What I have been told to change it to, is this:

  • Contains at least one letter. (lowercase or uppercase, it should NOT be case sensitive)
  • Contains at least one number.
  • Contains at least 6 characters.

This system is very small, and even though I was against it at first, I see that it is a bit overkill to have these restrictions for our system, even though it makes it a lot safer. The reason we are changing this is because of all the workers forgetting their passwords all the time because of these restrictions.

I have tried to remove some of the code from the variable re but since I am not 100% sure what exactly I am removing, I wanted to ask help here. What should I change in order to get the system to accept a password with the restrictions I want it to?

Removing (?=.*[A-Z]) didn't do it, since it is still case sensitive. Thanks in advance.

(I know some of you probably wouldn't recommend doing these things in javascript since it's client side, but none of our users will have any interest (nor idea) of how to get around these restrictions).

2 Answers 2

1

How about:

var re = /(?=.*\d)(?=.*[a-zA-Z]).{6,}/;

or

var re = /(?=.*\d)(?=.*[a-z]).{6,}/i;
Sign up to request clarification or add additional context in comments.

1 Comment

I think I can see the difference, these two does the same thing right? So I better just go with the shortest I guess. Thanks!
1
var re = /(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,}/i;

At easiest

A little explanation: there are a bunch of modifiers that you can apply to regex patterns. i is for case-insensitive match

2 Comments

lol seriously?.. I have one question, what happens if we do this: var re = /(?=.*\d)(?=.*[a-z]).{6,}/i; then?
@PHPeter I hate reading regex because it hurts my brain, I just went and gave you the easiest solution that would do the job for you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.