Hello Beaker,
I was reading the documentation of crypt and I noticed from the sample code:
if (crypt($word, $pwd) ne $pwd) {
die "Sorry...\n";
} else {
print "ok\n";
}
They are using first the word and then the password. It is not related to your problem but I think it would be more clear in future reference:
my $cryptedpass = crypt($passwrd1, substr($never_blank_value, 0, 2));
The only reason that I can imagine that you might have $cryptedpass as blank is that you have $never_blank_value. You are using substr and you are cutting off the first 2 characters of the string. In case the string it has less than 2 characters then you will end up with undef value. Sample of proposed code:
#!/usr/bin/perl
use strict;
use warnings;
use feature 'say';
my $never_blank_value = 'T';
my @passset = ('a'..'k', 'm'..'n', 'p'..'z', '2'..'9');
my $passwrd1 = "";
for (my $i=0; $i<8; $i++) {
$passwrd1 .= $passset[int(rand($#passset + 1))];
}
die 'Too small \$never_blank_value' if length $never_blank_value < 2;
my $cryptedpass = crypt($passwrd1, substr($never_blank_value, 0, 2));
say $cryptedpass;
__END__
$ perl test.pl
Too small \$never_blank_value at test.pl line 13.
Sample of error:
#!/usr/bin/perl
use strict;
use warnings;
use feature 'say';
my $never_blank_value = 'T';
my @passset = ('a'..'k', 'm'..'n', 'p'..'z', '2'..'9');
my $passwrd1 = "";
for (my $i=0; $i<8; $i++) {
$passwrd1 .= $passset[int(rand($#passset + 1))];
}
# die 'Too small \$never_blank_value' if length $never_blank_value < 2
+;
my $cryptedpass = crypt($passwrd1, substr($never_blank_value, 0, 2));
say $cryptedpass;
__END__
perl test.pl
Use of uninitialized value $cryptedpass in say at test.pl line 15.
Update: Based on the link 0007695: Crypt bug that fellow Monk poj point it out you might be passing non acceptable characters. If this is the case add this to your code:
die 'Not accepted characters at \$never_blank_value'
unless ($never_blank_value =~ /^[a-zA-Z0-9.\/]+$/);
Hope this helps, BR.
Seeking for Perl wisdom...on the process of learning...not there...yet!
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.