Checking password input with regular expression

Discussion in 'ASP .Net' started by JJ, Sep 18, 2006.

  1. JJ

    JJ Guest

    To validate a password as the user is registering I want to use a regular
    expressio validator.

    I got this one from the Microsoft web site for validating a password of at
    least 7 characters, with at least one number and one non-alphanumeric
    character:

    @\"(?=.{7,})(?=(.*\d){1,})(?=(.*\W){1,})

    Yet I can't get it to validate that a password like qwertyui123# fits the
    criteria.

    Or any password for that matter. Can anyone help with a regular expression
    that works? or am I goong wrong somewhere?

    JJ
     
    JJ, Sep 18, 2006
    #1
    1. Advertisements

  2. JJ

    Markus Palme Guest

    > I got this one from the Microsoft web site for validating a password of at
    > least 7 characters, with at least one number and one non-alphanumeric
    > character:
    >
    > @\"(?=.{7,})(?=(.*\d){1,})(?=(.*\W){1,})
    >
    > Yet I can't get it to validate that a password like qwertyui123# fits the
    > criteria.


    @\"(?=.{7,})(?=(.*\d){1,})(?=(.*\w){1,})

    This one works, just a typing mistake.

    Markus
     
    Markus Palme, Sep 18, 2006
    #2
    1. Advertisements

  3. JJ

    ThunderMusic Guest

    it does not work for me... is there something I should know? I tested it
    on this site : http://regexlib.com/RETester.aspx?regexp_id=887 and it never
    matches.

    thanks

    ThunderMusic

    "Markus Palme" <> a écrit dans le message de news:
    ...
    >> I got this one from the Microsoft web site for validating a password of
    >> at
    >> least 7 characters, with at least one number and one non-alphanumeric
    >> character:
    >>
    >> @\"(?=.{7,})(?=(.*\d){1,})(?=(.*\W){1,})
    >>
    >> Yet I can't get it to validate that a password like qwertyui123# fits
    >> the
    >> criteria.

    >
    > @\"(?=.{7,})(?=(.*\d){1,})(?=(.*\w){1,})
    >
    > This one works, just a typing mistake.
    >
    > Markus
    >
     
    ThunderMusic, Sep 19, 2006
    #3
  4. JJ

    JJ Guest

    Markus,

    Surely by changing the 'W' to 'w' you are not looking for patterns with
    non-alphanumeric characters in it?

    the (?=*\W){1}) means the pattern must have one or more non-alphanumeric
    characters in it.

    I think the problem lies with the initial @\" . Clearly the expression is
    trying to match a pattern that does not have a '@' or a ' " ' in it, but if
    you remove this part of the expression, it works as expected, allbeit
    allowing those 2 'disallowed' characters.

    Anyone work out what the correct notation should be?

    JJ

    "Markus Palme" <> wrote in message
    news:...
    >> I got this one from the Microsoft web site for validating a password of
    >> at
    >> least 7 characters, with at least one number and one non-alphanumeric
    >> character:
    >>
    >> @\"(?=.{7,})(?=(.*\d){1,})(?=(.*\W){1,})
    >>
    >> Yet I can't get it to validate that a password like qwertyui123# fits
    >> the
    >> criteria.

    >
    > @\"(?=.{7,})(?=(.*\d){1,})(?=(.*\w){1,})
    >
    > This one works, just a typing mistake.
    >
    > Markus
    >
     
    JJ, Sep 19, 2006
    #4
  5. JJ

    Markus Palme Guest

    JJ schrieb:

    > Markus,
    >
    > Surely by changing the 'W' to 'w' you are not looking for patterns with
    > non-alphanumeric characters in it?


    My mistake, sorry - I missed the "non-"alphanumeric. The regex of
    course, is only this part:

    (?=.{7,})(?=(.*\d){1,})(?=(.*\w){1,})

    Markus
     
    Markus Palme, Sep 19, 2006
    #5
  6. JJ

    JJ Guest

    Sorry Markus I still can't see that it makes sense to me.

    If I am searching for a pattern that matches 7 or more characters containing
    1 or more digits and 1 or more non-alphanumeric characters,
    I can't see how this would work.

    I understand I may be going wrong somewhere, but where?

    The original @\" at the beginning was meant to make sure that those
    characters are not part of the password. So, as far as I can see they do
    need to be part of the regular expression.

    JJ



    "Markus Palme" <> wrote in message
    news:...
    >
    > JJ schrieb:
    >
    >> Markus,
    >>
    >> Surely by changing the 'W' to 'w' you are not looking for patterns with
    >> non-alphanumeric characters in it?

    >
    > My mistake, sorry - I missed the "non-"alphanumeric. The regex of
    > course, is only this part:
    >
    > (?=.{7,})(?=(.*\d){1,})(?=(.*\w){1,})
    >
    > Markus
    >
     
    JJ, Sep 19, 2006
    #6
  7. JJ

    JJ Guest

    How about this one:

    ^.*(?=.{7,})(?=.*\d)(?=.*[a-zA-Z])(?=.*[@#$%^&+=]).*$

    That breaks down as:

    7 characters;
    must contain a digit;
    must contain a character in the range a-z or A-Z;
    must contain one of these characters @#$%^&+=

    I've run some quick tests and its seems to work for me, but be grateful for
    anyone elses views?

    JJ




    "JJ" <> wrote in message
    news:ua%...
    > Sorry Markus I still can't see that it makes sense to me.
    >
    > If I am searching for a pattern that matches 7 or more characters
    > containing 1 or more digits and 1 or more non-alphanumeric characters,
    > I can't see how this would work.
    >
    > I understand I may be going wrong somewhere, but where?
    >
    > The original @\" at the beginning was meant to make sure that those
    > characters are not part of the password. So, as far as I can see they do
    > need to be part of the regular expression.
    >
    > JJ
    >
    >
    >
    > "Markus Palme" <> wrote in message
    > news:...
    >>
    >> JJ schrieb:
    >>
    >>> Markus,
    >>>
    >>> Surely by changing the 'W' to 'w' you are not looking for patterns with
    >>> non-alphanumeric characters in it?

    >>
    >> My mistake, sorry - I missed the "non-"alphanumeric. The regex of
    >> course, is only this part:
    >>
    >> (?=.{7,})(?=(.*\d){1,})(?=(.*\w){1,})
    >>
    >> Markus
    >>

    >
    >
     
    JJ, Sep 19, 2006
    #7
  8. JJ

    ThunderMusic Guest

    ok, so Here it is, the supreme regex for passwords... ;)

    ^.*(?=.{7,})((?=.*\d)(?=.*[a-z])(?=.*[A-Z])|(?=.*\d)(?=.*[a-z])(?=.*[^a-zA-Z0-9])|(?=.*\d)(?=.*[A-Z])(?=.*[^a-zA-Z0-9])|(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9])).*$

    it tests for 3 of these 4 cases : 1 a-z, 1 A-Z, 1 digit, 1 non-alphanumeric.
    7 chars minimum... you can test it, it works fine... I'll add it to my
    validations.

    I hope helps

    ThunderMusic


    "JJ" <> wrote in message
    news:...
    > How about this one:
    >
    > ^.*(?=.{7,})(?=.*\d)(?=.*[a-zA-Z])(?=.*[@#$%^&+=]).*$
    >
    > That breaks down as:
    >
    > 7 characters;
    > must contain a digit;
    > must contain a character in the range a-z or A-Z;
    > must contain one of these characters @#$%^&+=
    >
    > I've run some quick tests and its seems to work for me, but be grateful
    > for anyone elses views?
    >
    > JJ
    >
    >
    >
    >
    > "JJ" <> wrote in message
    > news:ua%...
    >> Sorry Markus I still can't see that it makes sense to me.
    >>
    >> If I am searching for a pattern that matches 7 or more characters
    >> containing 1 or more digits and 1 or more non-alphanumeric characters,
    >> I can't see how this would work.
    >>
    >> I understand I may be going wrong somewhere, but where?
    >>
    >> The original @\" at the beginning was meant to make sure that those
    >> characters are not part of the password. So, as far as I can see they do
    >> need to be part of the regular expression.
    >>
    >> JJ
    >>
    >>
    >>
    >> "Markus Palme" <> wrote in message
    >> news:...
    >>>
    >>> JJ schrieb:
    >>>
    >>>> Markus,
    >>>>
    >>>> Surely by changing the 'W' to 'w' you are not looking for patterns with
    >>>> non-alphanumeric characters in it?
    >>>
    >>> My mistake, sorry - I missed the "non-"alphanumeric. The regex of
    >>> course, is only this part:
    >>>
    >>> (?=.{7,})(?=(.*\d){1,})(?=(.*\w){1,})
    >>>
    >>> Markus
    >>>

    >>
    >>

    >
    >
     
    ThunderMusic, Sep 19, 2006
    #8
    1. Advertisements

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. VSK
    Replies:
    2
    Views:
    2,442
  2. =?Utf-8?B?SXZhbiBBYnJhbW92?=

    Regular expression for password

    =?Utf-8?B?SXZhbiBBYnJhbW92?=, Jan 29, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    350
    Jonathan Wood
    Jan 29, 2007
  3. Chris

    Regular Expression in password

    Chris, Feb 3, 2007, in forum: ASP .Net
    Replies:
    4
    Views:
    375
    =?ISO-8859-1?Q?G=F6ran_Andersson?=
    Feb 4, 2007
  4. AAaron123
    Replies:
    2
    Views:
    2,465
    AAaron123
    Jan 16, 2009
  5. AAaron123
    Replies:
    1
    Views:
    1,458
    Oriane
    Jan 16, 2009
Loading...

Share This Page