snix123
asked on
password validation - no repeating patternsmore than twice in succession
Hi experts:
I have a requirement to validate passwords using the usual criteria, but one interesting one. I must make sure the password does not contain characters repeating more than once in a succession. The password can only be 20 characters long. The requirement means the following:
Legal passwords may contain: abcabc, dd, !&!&, rere
Illegal passwords: abcabcabc, ddd, !&!&!&, rerere
I hope this makes sense. I am working in coldfusion 8. I am trying to use a regular expression, but I think I need to do some sort of recurssion.
Any ideas? Thanks in advance. If you could point me in the right direction, that would be a big help.
I have a requirement to validate passwords using the usual criteria, but one interesting one. I must make sure the password does not contain characters repeating more than once in a succession. The password can only be 20 characters long. The requirement means the following:
Legal passwords may contain: abcabc, dd, !&!&, rere
Illegal passwords: abcabcabc, ddd, !&!&!&, rerere
I hope this makes sense. I am working in coldfusion 8. I am trying to use a regular expression, but I think I need to do some sort of recurssion.
Any ideas? Thanks in advance. If you could point me in the right direction, that would be a big help.
I am a bit confused by your requirement, so I am posting two patterns--you can pick which applies to you :)
Both validate that the string is 20 characters.
Both validate that the string is 20 characters.
// This will match if a series of characters
// are found repeating twice anywhere in
// the string (e.g. abchelloabcthereabc)
^(?=.*?(.+).*?\1.*?\1.*?).{1,20}$
// This will match if a series of characters
// are found repeating twice immediately in
// succession (e.g. abcabcabc)
^(?=.*?(.+)\1\1.*?).{1,20}$
ASKER
Thank you. I already have the 20 characters limit working. For the second pattern, I think I would just try to use this: ^(?=.*?(.+)\1\1.*?) since I don't need to test the length here. Can't seem to make it work without testing length, too.
I will play around with it. The backreferenceing doc is helping, too.
I will play around with it. The backreferenceing doc is helping, too.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks to all: this is looking pretty good.
NP. Glad to help :)
Try this regex:
^(.+?)(\1)$
The adobe website has an example of capturing repeating words here:
https://www.adobe.com/livedocs/coldfusion/6/Developing_ColdFusion_MX_Applications_with_CFML/regexp4.htm#1099092
Read the section on using backreferences.
Hope this helps.
P.