[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

PHP Password RegEx

Posted on 2006-11-25
8
Medium Priority
?
512 Views
Last Modified: 2010-05-18
Hi,

I'm trying to produce a regex for a password with the following requirements:
Min. 8 characers with at least two digits/numbers

Two or more numbers anywhere in a string...how does that translate to a regex?

(?=.*/d) is at least one number, but I cannot figure out how to do at least two numbers.

Thanks!
0
Comment
Question by:evco
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 1

Assisted Solution

by:ictinus
ictinus earned 100 total points
ID: 18013668


http://www.ultrapico.com/ExpressoDownload.htm

this may or may not work honestly I didn't take time to learn the program but it proclaims itselft to be a regex builder.  hopefully it's usefull to you.  
0
 
LVL 8

Accepted Solution

by:
John Kawakami earned 200 total points
ID: 18013731
You have to use two tests.

/.*\d.*\d.*/  -- tests that there are two digits

and

strlen() test for length

0
 
LVL 29

Assisted Solution

by:TeRReF
TeRReF earned 100 total points
ID: 18013873
How about:

<?php

function checkPasswd($pw) {
        if ((preg_match('/^.*\d+.*\d+.*?$/', $pw, $match)) === 1)
                if (strlen($match[0]) > 7)
                        return true;
        return false;
}

$s = 'pass2word6';
if (checkPasswd($s) === true)
        echo 'Good Password';
else
        echo 'Bad Password';

?>
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:evco
ID: 18014298
Is it impossible to do the length check within the regex? It would be preferrable that way.
0
 
LVL 16

Assisted Solution

by:HackneyCab
HackneyCab earned 100 total points
ID: 18014708
As far as I know, it's not possible to enforce a length using regex where you have more than one character class, so you are best off using the strlen() function in PHP.

Is there a reason why you don't want to use strlen()?
0
 

Author Comment

by:evco
ID: 18014916
I'm using the PEAR QuickForm class and passing a regex to validate the password field. Obviously, I can work around that and use the strlen() function.

Thanks all, for your help.
0
 
LVL 8

Expert Comment

by:John Kawakami
ID: 18015650
If you can pass two regexs to the validation thing, you can also do this:
/.{8,}/

That will specify that there are 8 chars or more.
0
 

Author Comment

by:evco
ID: 18019621
:) Thanks, jk2001
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question