Solved

Perl - check names in varible

Posted on 2011-02-23
5
418 Views
Last Modified: 2012-05-11
I have an issue where I need up update our password checker so that when a user resets their password a check is made to make sure the new password does not contain the users First or Last name.

I have a sample script for a check below, the issue I have is that we have many users that has multiple names in their First or Last name, so in the sample below the check would work if I changed the Fist or Last name to just one word.

How can I fix the check to break down the multiple names in the First or Last name (if exists) then do the test on each of the words in the Fist or Last name.


#! /usr/bin/perl
use strict;
use warnings;

my $newPassword = 'Billy#123';
my $firstName = 'John Doe';
my $lastName = 'Billy Ray';

my @wordsInNames;
push(@wordsInNames, "$firstName", "$lastName");

foreach my $wd (@wordsInNames) {
 if ($newPassword =~ /$wd/) {
   print "Found name in password: $wd\n";
 }
}

Open in new window

0
Comment
Question by:bt707
5 Comments
 
LVL 26

Accepted Solution

by:
wilcoxon earned 350 total points
ID: 34965649
This should work.  It currently breaks names down based on space or hyphen.
#! /usr/bin/perl
use strict;
use warnings;

my $newPassword = 'Billy#123';
my $firstName = 'John Doe';
my $lastName = 'Billy Ray';

my @wordsInNames;
push @wordsInNames, split(/[-\s]/, $firstName);
push @wordsInNames, split(/[-\s]/, $lastName);

foreach my $wd (@wordsInNames) {
 if ($newPassword =~ /$wd/i) {
   print "Found name in password: $wd\n";
 }
}

Open in new window

0
 
LVL 5

Assisted Solution

by:group0
group0 earned 75 total points
ID: 34965652
#! /usr/bin/perl
use strict;
use warnings;

my $newPassword = 'Billy#123';
my $firstName = 'John Doe';
my $lastName = 'Billy Ray';

my @wordsInNames = split(/ /, "$firstName $lastName");

foreach my $wd (@wordsInNames) {
 if ($newPassword =~ /$wd/) {
   print "Found name in password: $wd\n";
 }
}

Open in new window

0
 
LVL 16

Assisted Solution

by:sjklein42
sjklein42 earned 75 total points
ID: 34965656
This change will split the first name and last name on spaces.  I think it is what you want.

#! /usr/bin/perl
use strict;
use warnings;

my $newPassword = 'Billy#123';
my $firstName = 'John Doe';
my $lastName = 'Billy Ray';

my @wordsInNames;
push(@wordsInNames, split(/\s+/,$firstName), split(/\s+/,$lastName));

foreach my $wd (@wordsInNames) {
 if ($newPassword =~ /$wd/) {
   print "Found name in password: $wd\n";
 }
} 

Open in new window

0
 
LVL 16

Expert Comment

by:sjklein42
ID: 34965667
How many ways to skin a cat!  I wish I hadn't delayed to test mine!
0
 

Author Closing Comment

by:bt707
ID: 34965689
Thanks for all the quick answers, I had tried the one from wilcoxon when posted and worked fine, I'm sure all other did the same, just was not sure how to spit the names for the checks.

Thanks All !!!!
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question