Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Regex for a Complex Password

Last post 03-29-2007, 12:06 PM by mash. 16 replies.
Page 1 of 2 (17 items)   1 2 Next >
Sort Posts: Previous Next
  •  03-21-2007, 11:50 PM 28368

    Regex for a Complex Password

    HI Friends

    It would be greatly helpful if you could help me out with the following description for a password

    The Password must be a minimum of 8 characters in combination of alpha, numeric, and/or special characters with no more than 2 repeating characters. The password may contain some of all 3 character sets, however it must minimally use a combination of 2 of the 3 character sets (ie, alpha + numeric, special character + numeric, etc.)
     the special characters accepted will be

    ! @ # $ % ^ & * ( ) _ + - = .

    ! @ # $ % ^ & * ( ) _ + - = .

    (will have to use the regex in validator.xml- STRUTS)

     Thanks in advance !!

    Filed under:
  •  03-22-2007, 12:50 AM 28369 in reply to 28368

    Re: Regex for a Complex Password

    As much as this question gets asked (and answered) why does no one ever specify which characters they consider special? PLEASE read the posting guidelines and repost your question.
          

    Michael

    "In theory, theory and practice are the same. In practice, they are not."
    Albert Einstein
  •  03-22-2007, 1:26 AM 28370 in reply to 28368

    Re: Regex for a Complex Password

    Sorry for not mentioning this before : the special characters accepted will be

    !@#$%^&*()_+-=.

  •  03-22-2007, 1:26 AM 28371 in reply to 28368

    Re: Regex for a Complex Password

    Sorry for not mentioning this before : the special characters accepted will be

    !@#$%^&*()_+-=.

  •  03-22-2007, 4:16 PM 28417 in reply to 28371

    Re: Regex for a Complex Password

    ^(((?=.*?\p{L})(?=.*?\d))|((?=.*?\p{L})(?=.*?[!@#$%^&*()+=._-]))|((?=.*?[!@#$%^&*()+=._-])(?=.*?\d)))[-!@#$%^&*()+=.\w]{8,}$

     I don't remember is struts used a regex engine that supports Look-aheads, you'll have to check.  Also check to see if unicode syntax is supported


    Michael

    "In theory, theory and practice are the same. In practice, they are not."
    Albert Einstein
  •  03-23-2007, 8:43 AM 28441 in reply to 28417

    Re: Regex for a Complex Password

    i tried testing it .. but the symbol L was not recognised !! - it says unrecognized unicode character class
    i used "Expresso" to test the regular expressions

  •  03-23-2007, 12:12 PM 28449 in reply to 28441

    Re: Regex for a Complex Password

    karunkarthik:

    i tried testing it .. but the symbol L was not recognised !! - it says unrecognized unicode character class
    i used "Expresso" to test the regular expressions

    Expresso doesn't recognize L? wow.  I don't use that tool myself but can some who does confirm this.  Of the unicode properties it's one of the more basics.  I would think if it didn't supprot that one it wouldn't support any.  I thought Expresso used the .Net regex engine? if so that can't be right it would be a bug with that program.

    Anyway should not test with a different regex engine than you are going to actually use.  That's just asking for headaches.
     


    Michael

    "In theory, theory and practice are the same. In practice, they are not."
    Albert Einstein
  •  03-23-2007, 1:04 PM 28451 in reply to 28449

    Re: Regex for a Complex Password

    just checked it out in Expresso v2.1:

    regex

    p{L}+

    does not mach on text

    abc

    regex

    p{L}

    matches on text

    p{L}

    i.e apparently Expresso treates *p{L}* as a sequence of literals.

  •  03-23-2007, 2:44 PM 28454 in reply to 28451

    Re: Regex for a Complex Password

    Sergei Z:

    just checked it out in Expresso v2.1:

    regex

    p{L}+

    does not mach on text

    abc

    regex

    p{L}

    matches on text

    p{L}

    i.e apparently Expresso treates *p{L}* as a sequence of literals.

     

    Sergei,

    It would be

    \p{L}

    not

    p{L}  that would be a literal 

    I checked with the beta new version and it worked 


    Michael

    "In theory, theory and practice are the same. In practice, they are not."
    Albert Einstein
  •  03-24-2007, 2:15 AM 28461 in reply to 28454

    Re: Regex for a Complex Password

    hey

    i used expresso 3.0 beta for testing .. the regex did not work there ..
    in the regex analyser pane this is what i got : Possibly unrecognised Unicode Character class :[L] .

    i know it might be asking for a bit too much .. i'm relatively new to Regular Expressions ..  so it would be great if u could give a small description of the regex u give ..

    (for eg . where is the check for not more than two repeating characters happening ?? )

    thanks a ton ..

  •  03-24-2007, 2:27 AM 28462 in reply to 28454

    Re: Regex for a Complex Password

    And also .. i dunno wht regex engine is involved in my case ..
    i am using this to validate a password using the validation feature in STRUTS .. a file validation.xml is where i am goin to give the regex .. the validation occurs in validator-rules.xml .. (all built in files in Struts Validator Framework )
    i think the parser used here is SAX parser ..
    please do correct me if there is something wrong in the above .
  •  03-25-2007, 12:47 AM 28472 in reply to 28461

    Re: Regex for a Complex Password

    karunkarthik:

    hey

    i used expresso 3.0 beta for testing .. the regex did not work there ..
    in the regex analyser pane this is what i got : Possibly unrecognised Unicode Character class :[L] .

    i know it might be asking for a bit too much .. i'm relatively new to Regular Expressions ..  so it would be great if u could give a small description of the regex u give ..

    (for eg . where is the check for not more than two repeating characters happening ?? )

    thanks a ton ..

    My bad I forgot about the repeating character requirement, but before we get to that let just clear something up.  I don't know what you are but there is nothing wrong with the syntax of the previous regex I gave you and it works prefectly fine in Expresso 2.1 and 3.0  I've tested with both got no error message either time.

    Now this regex

    ^(?!.*(.)\1{2})(((?=.*?\p{L})(?=.*?\d))|((?=.*?\p{L})(?=.*?[!@#$%^&*()+=._-]))|((?=.*?[!@#$%^&*()+=._-])(?=.*?\d)))([-!@#$%^&*()+=.\w]){8,}$

    meets all of your requirement and it ran in Expresso.  There was another problem  with the results but that's not important

    karunkarthik:

    And also .. i dunno wht regex engine is involved in my case ..
    i am using this to validate a password using the validation feature in STRUTS .. a file validation.xml is where i am goin to give the regex .. the validation occurs in validator-rules.xml .. (all built in files in Struts Validator Framework )
    i think the parser used here is SAX parser ..
    please do correct me if there is something wrong in the above .

    Secondly if you are using Struts you are going to be using a java regex engine, I think it's Jakarta ORO but I don't remember. It could be the other Jakarta regex project (REGEXP) or another regex engine altogether. But I think it's ORO.  The reason we ask in the posting guidelines what you are programming in is because all regex engines are not created equal.  The more advanced features aren't always supported and occasionally there are syntax differences.

    Neither of the Jakarta projects support the Unicode syntax so even  if you figured out what you did wrong in Expresso and got it working there it would not work for Struts. If you followed the link to the blog entry you should now understand why you should not be testing regexes in Expresso that you are planing to use in Struts (unless it's very very simple)

     Now if I relax your original criteria some and reduce alphas just the english alphabet, which might have been all you really wanted but you didn't say that, this regex

    ^(?!.*(.)\1{2})(((?=.*?[a-zA-Z])(?=.*?\d))|((?=.*?[a-zA-Z])(?=.*?[!@#$%^&*()+=._-]))|((?=.*?[!@#$%^&*()+=._-])(?=.*?\d)))([-!@#$%^&*()+=._\da-zA-Z]){8,}$

    works with Jakarta ORO, which is probably what you need to test any regex you are going to use with Struts, unless you find Struts is using some other regex engine.  Now if you really meant alphas that would require a different regex.
     

     Finally here is the first regex  in this post with comments

    ^(?!.*(.)\1{2}) #No more than 2 repeating characters
     (((?=.*?\p{L})(?=.*?\d)) #Letters and numbers
     |((?=.*?\p{L})(?=.*?[!@#$%^&*()+=._-])) #Letters and Special characters
     |((?=.*?[!@#$%^&*()+=._-])(?=.*?\d)) #Special Characters and digits
     )([-!@#$%^&*()+=.\w]){8,}$ #8 or more of the allowed characters


    Michael

    "In theory, theory and practice are the same. In practice, they are not."
    Albert Einstein
  •  03-26-2007, 11:18 PM 28550 in reply to 28472

    Re: Regex for a Complex Password

    Hi Michael
    Thanks a lot for the regex .. it dint quite work in my application .. no idea why ..
    i did learn a bit abt regular expressions from u .. thanks a lot ..
    there is another doubt i have .. in the above regex  in the check for 'no more than 2 repeating chars' - it checks only for same character repeating more than twice provided they are consecutive .. how do  i check for characters that occur more than twice in the string and are not necessarily consecutive ..

    (i.e)
    *aaa* -> invalid
    *a*a*a* -> also should not be allowed !!

    Thanks a lot ..

  •  03-27-2007, 12:13 AM 28552 in reply to 28550

    Re: Regex for a Complex Password

    ^((?!(.*?\1){2})[a-z])+$

    will match on

    abacdd

    but fail on

    abacad

  •  03-29-2007, 7:17 AM 28593 in reply to 28552

    Re: Regex for a Complex Password

    i tried my best to include the above check in this regex ..  ^(?!.*(.)\1{2})(((?=.*?[a-zA-Z])(?=.*?\d))|((?=.*?[a-zA-Z])(?=.*?[!@#$%^&*()+=._-]))|((?=.*?[!@#$%^&*()+=._-])(?=.*?\d)))([-!@#$%^&*()+=._\da-zA-Z]){8,}$  ... Never worked for me .. Could u please help !!
Page 1 of 2 (17 items)   1 2 Next >
View as RSS news feed in XML