- To: Stuart Guthrie <stuart@xxxxxxxxxxxxxxxx>
- Subject: Re: [SLUG] RegEx question
- From: Glen Turner <gdt@xxxxxxxxx>
- Date: Fri, 9 Nov 2007 17:27:45 +1030 (CST)
- Cc: SLUG list <slug@xxxxxxxxxxx>
On Fri, 9 Nov 2007, Stuart Guthrie wrote:
Field that must have 2 out of 3 of these:
standard a-z/A-Z
arabic numbers 0-9
special chars %$#@
What's wrong with brute force?
bool password_characters_good_choice(char *s) {
int matches;
matches = (match("abcdefghijklmnopqrstuvwxyz", s) +
match("ABCDEFGHIJKLMNOPQRSTUVWXYZ", s) > 0);
matches += (match("0123456789", s) > 0);
matches += (match("%$#@", s) > 0);
return (matches > 2);
}
where match(s1, s2) returns the number of occurances of
the characters of s1 in s2. That's pretty easy to implement
and is a prewritten function in a lot of languages.
Cheers, Glen