Solved

Perl - check names in varible

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

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 …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

705 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

20 Experts available now in Live!

Get 1:1 Help Now