Solved

Perl - check names in varible

Posted on 2011-02-23
5
432 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…

751 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