Click here to get back home

Regex for password checking

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Regex for password checking Owen 05-23-2008
Get Chitika Premium
Posted by Owen on May 23, 2008, 11:16 pm
Please log in for more thread options
Hi,

Just wondering if [:print:], with a pretest for a space would meet all
the requirements of a unix password. (mixed case, numbers, and
symbols)

Or is there some easier way of doing it?

TIA


Owen


#!/usr/bin/perl -w

use strict;

while (<DATA>) {
chomp;
my $new_pass = $_;
if ( $new_pass =~ / / ) { print "$new_pass Error, contains space
\n" }

#unless ( $new_pass =~ /[a-zA-Z0-9_\^\.\|\(\)\[\]\`~!@#%&*;:'"+,?
\/><]/ )
#unless ( $new_pass =~ /[[:alnum:]_\^\.\|\(\)\[\]\`~!@#%&*;:'"+,?
\/]></ )

#unless ( $new_pass =~ /[[:alnum:][:print:]]/ )
unless ( $new_pass =~ /[[:print:]]/ )
{
print "$new_pass Error, not printable\n";
}
}

__DATA__
Ddfrew3>
cF4444!,

Posted by Joe Smith on May 24, 2008, 2:44 am
Please log in for more thread options
Owen wrote:
> Just wondering if [:print:], with a pretest for a space would meet all
> the requirements of a unix password. (mixed case, numbers, and
> symbols)
>
> Or is there some easier way of doing it?

I'd say it is more straightforward to make such tests one at a time.

my $good = 0;
++$good if /[a-z]/;
++$good if /[A-Z]/;
++$good if /[0-9]/;
++$good if /\W/;
redo unless $good >= 3;

        -Joe
Doctor Who?

Posted by Tad J McClellan on May 24, 2008, 9:44 am
Please log in for more thread options

> Just wondering if [:print:], with a pretest for a space would meet all
> the requirements of a unix password. (mixed case, numbers, and
> symbols)


A "unix password" _can_ have space characters in it.


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher0cmdat/"

Similar ThreadsPosted
Checking to see if PID is running September 27, 2005, 1:55 am
checking for filehandle March 19, 2007, 5:56 am
checking file age January 15, 2008, 10:46 am
checking existance of a directory January 20, 2005, 1:06 am
Checking for safe paths March 9, 2005, 7:59 pm
Checking If A Function Exists July 11, 2005, 5:11 pm
Checking range of IP addresses July 23, 2005, 2:22 pm
Checking thread status August 4, 2005, 7:51 pm
Checking if a value in one hash exists in another November 19, 2005, 2:42 pm
Checking for undef after performing get() January 9, 2006, 5:01 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap