List Info

Thread: Check password with RegEx




Check password with RegEx
user name
2006-09-21 19:08:42
Hi everyone,
I am new to regular expressions and am working on a
"check password"
method using regex.

I have managed to create all checks in regular expressions
except the
following two:
 * First n characters should not contain the name (e.g. if
name is
"Peter" and we specify that name cannot be in
the first 8 characters,
then the text "12Peter2123fr" should validate
false).
 * Text should contain at least 1 lowercase char, 1
uppercase char, 1
number and 1 special char (!£$%&*#+-<>).

Can anyone help me with this?

Thanks,
David


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---

Check password with RegEx
user name
2006-09-25 16:29:50
how would u define 'name'? What chars constitute 'name'?
what is the
pattern for it? Until u know the rule(s) for 'name' u
cannot start
coding that constraint for the password..


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---

Check password with RegEx
user name
2006-09-25 19:30:31
Hi Sergei,
Name is a Windows username e.g. the name the user types in
when trying
to logon to a computer. Generally I guess it would be a
string of chars
e.g. "David", "Dav",
"de" etc. so that string in the exact order
should
not be in the n first chars of the password...

/David

Sergei Z wrote:
> how would u define 'name'? What chars constitute
'name'? what is the
> pattern for it? Until u know the rule(s) for 'name' u
cannot start
> coding that constraint for the password..


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---

Check password with RegEx
user name
2006-09-26 01:03:37
David Eliasen wrote:
> Hi everyone,
> I am new to regular expressions and am working on a
"check password"
> method using regex.
>
> I have managed to create all checks in regular
expressions except the
> following two:
>  * First n characters should not contain the name (e.g.
if name is
> "Peter" and we specify that name cannot be
in the first 8 characters,
> then the text "12Peter2123fr" should
validate false).
>  * Text should contain at least 1 lowercase char, 1
uppercase char, 1
> number and 1 special char (!£$%&*#+-<>).
>
> Can anyone help me with this?
>
> Thanks,
> David

First requirement is tricky: it requires a nested
look-ahead/look-behind to implement:

this regex

^(?!.(?<=Peter.*?).).{1,55}$

will do the job, it will not allow 'Peter' to be within
the first 8
chars of the password.

second req is trivial: u simply apply 4 look aheads in a row
: one for
each group of chars. The regex for both reqs is:

^(?-i)(?!.(?<=Peter.*?).)(?=.*?[a-z])(?=.*?[A-Z])(?=.*
?\d)(?=.*?[£$%&*#+<>).-]).{1,55}$

it'll validate:

vvvvPeter2123frvvvv.vv

it'll fail on:

vvvPeter2123frvvvv.vv

WArning: looks at option swith (?-i) : it is .NET specific
syntax for
turning OFF Ignore case mode; in your environment u might
change the
syntax accordingly. Anyway I tested it in
http://regexlib.com
/RETester.aspx, and it works according to your spec.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---

Check password with RegEx
user name
2006-09-26 01:08:34
forgot to tell u (i guess it's obvious) that the regex will
have to be
created on the fly, after the user inputs a userid. You know
it, I'm
sure.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---

Check password with RegEx
user name
2006-09-26 05:40:17
David Eliasen wrote:
> Hi everyone,
> I am new to regular expressions and am working on a
"check password"
> method using regex.
>
> I have managed to create all checks in regular
expressions except the
> following two:
>  * First n characters should not contain the name (e.g.
if name is
> "Peter" and we specify that name cannot be
in the first 8 characters,
> then the text "12Peter2123fr" should
validate false).

what's the language/tool you are using? Is the 'name'
field known or
generated on the fly??

If you can use Perl, you can do things like:
=======
my $str = '12Peter2123fr';
my $first_n_char = 8;
my $name = 'Peter';
my $len = $first_n_char - length($name);
print "Matched\n" if $str =~
/^(?!.{0,$len}$name)/;

In another word, if you know the 'name' field is 'Peter'
which has
exactly 5 characters, then the pattern is like:

    ^(?!.{0,3}Peter)

>  * Text should contain at least 1 lowercase char, 1
uppercase char, 1
> number and 1 special char (!£$%&*#+-<>).

This part is pretty much like an FAQ in this group, 

 
(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!£\$%&*#+<>-
])

so, by grouping both requirements, your pattern can be like:

   
^(?!.{0,3}Peter)(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!£\$%&
amp;*#+<>-])

Regards,
Xicheng


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---

Check password with RegEx
user name
2006-09-26 17:07:18
Xicheng,

thanks for posting the solution. U always seem to find the
easiest
solutuions possible: my nested look-behind was clearly an
overkill ;=).


See u around,

Sergei


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---

[1-7]

about | contact  Other archives ( Real Estate discussion Medical topics )