Regex for password policy

Discussion in 'Java' started by frank_ratzlow@hotmail.com, Jul 18, 2005.

  1. Guest

    Hi folks,

    how can I merge these requirements into one regex?
    string shall be comprised of chars from following sequences: A-Z; a-z;
    0-9
    string shall at least have 8 chars
    at least one upper case letter should be contained (at any position)
    at least one number should be contained (at any position)

    Any idea?

    TIA

    Frank
     
    , Jul 18, 2005
    #1
    1. Advertising

  2. shakah Guest

    wrote:
    > Hi folks,
    >
    > how can I merge these requirements into one regex?
    > string shall be comprised of chars from following sequences: A-Z; a-z;
    > 0-9
    > string shall at least have 8 chars
    > at least one upper case letter should be contained (at any position)
    > at least one number should be contained (at any position)
    >
    > Any idea?
    >
    > TIA
    >
    > Frank
    >


    Would multiple regex's work for you, maybe:

    if( Pattern.matches("[A-Za-z0-9]{8,}", sPwd)
    && Pattern.matches(".*[A-Z].*", sPwd)
    && Pattern.matches(".*[0-9].*", sPwd)) {
    // ...woo hoo!
    }
     
    shakah, Jul 18, 2005
    #2
    1. Advertising

  3. "shakah" <> schrieb im Newsbeitrag
    news:...
    > wrote:
    >> Hi folks,
    >>
    >> how can I merge these requirements into one regex?
    >> string shall be comprised of chars from following sequences: A-Z; a-z;
    >> 0-9
    >> string shall at least have 8 chars
    >> at least one upper case letter should be contained (at any position)
    >> at least one number should be contained (at any position)
    >>
    >> Any idea?
    >>
    >> TIA
    >>
    >> Frank
    >>

    >
    > Would multiple regex's work for you, maybe:
    >
    > if( Pattern.matches("[A-Za-z0-9]{8,}", sPwd)
    > && Pattern.matches(".*[A-Z].*", sPwd)
    > && Pattern.matches(".*[0-9].*", sPwd)) {
    > // ...woo hoo!
    > }
    >

    there is no pattern for AND, but you can use "|" = OR.
    So if you want to check what is not allowed you can do the following
    "(.*[^a-zA-Z0-9].*)|(.{0,7})|([^A-Z]*)|([^0-9]*)"

    feri
     
    Ferenc Hechler, Jul 18, 2005
    #3
  4. SheikhG1900

    Joined:
    Apr 22, 2011
    Messages:
    1
    SheikhG1900, Apr 22, 2011
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    7,931
    Juan T. Llibre
    Mar 10, 2006
  2. AAaron123
    Replies:
    2
    Views:
    2,219
    AAaron123
    Jan 16, 2009
  3. AAaron123
    Replies:
    1
    Views:
    1,362
    Oriane
    Jan 16, 2009
  4. Nils Magnus Englund

    AD password policy in Forms auth against AD

    Nils Magnus Englund, Dec 17, 2004, in forum: ASP .Net Security
    Replies:
    3
    Views:
    161
    Joe Kaplan \(MVP - ADSI\)
    Dec 18, 2004
  5. Dabbler

    tighten password policy

    Dabbler, Aug 2, 2006, in forum: ASP .Net Security
    Replies:
    1
    Views:
    150
    Consultant
    Aug 2, 2006
Loading...

Share This Page