Solved

Perl - check names in varible

Posted on 2011-02-23
5
408 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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 …
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

914 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now