Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Perl - check names in varible

Posted on 2011-02-23
5
Medium Priority
?
439 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 27

Accepted Solution

by:
wilcoxon earned 1400 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 300 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 300 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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.…
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…
Six Sigma Control Plans

715 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