S
sopan.shewale
Hello,
I have Apache htpasswd format password store. The fields are ":"
separated and has more fields than standard format. I have script to
read the fields and load into Hash.
I need advice/help to improve the script. The current one works-but
not really good script. The script goes as follow:
--------------------------------
#!/usr/bin/perl
use strict;
use warnings;
my $data = {};
for (<DATA>) {
my $line = $_;
if ( defined $line ) {
if ( $line =~ /^(.*?).*?).*?).*?).*?)(?:.*))?$/
|| $line =~ /^(.*?).*?).*?).*?)(?:.*))?$/
|| $line =~ /^(.*?).*?).*?)(?:.*))?$/
|| $line =~ /^(.*?).*?)(?:.*))?$/ )
{
$data->{$1}->{pass} = $2;
$data->{$1}->{emails} = $3 || '';
$data->{$1}->{flag} =
( ( defined $4 ) && ( $4 == 0 ) ) ? 0 : ( $4 || '' );
$data->{$1}->{pass_change} = $5 || '';
$data->{$1}->{flag_change} = $6 || '';
}
}
}
use Data:umper;
print Data:umper->Dump( [$data] );
__DATA__
AllPresent:hjliEO35kCgwI:[email protected]:1:23232:24324
LastMissing:CyL92g3OKi.jM:[email protected]:1:2323
FlagZero:CyL92g3OKi.jM:[email protected]:0:23232
OnlyFlag:ZuqpLZ7AxHBvw[email protected]:0
RestMissing:ZuqpLZ7AxHBvw:[email protected]
-------------------------
Please note - only first two fields are must fields, rest may be
missing from lines. first is - username, second is encrypted
password, third is email, fourth is flag to force user to change
password(0-pass change is not required, 1-user must change pass),
fifth- the last time password changed epoch time, sixth- time of
change of flag (some times flag is changed by admins of the system).
thanks in advance
I have Apache htpasswd format password store. The fields are ":"
separated and has more fields than standard format. I have script to
read the fields and load into Hash.
I need advice/help to improve the script. The current one works-but
not really good script. The script goes as follow:
--------------------------------
#!/usr/bin/perl
use strict;
use warnings;
my $data = {};
for (<DATA>) {
my $line = $_;
if ( defined $line ) {
if ( $line =~ /^(.*?).*?).*?).*?).*?)(?:.*))?$/
|| $line =~ /^(.*?).*?).*?).*?)(?:.*))?$/
|| $line =~ /^(.*?).*?).*?)(?:.*))?$/
|| $line =~ /^(.*?).*?)(?:.*))?$/ )
{
$data->{$1}->{pass} = $2;
$data->{$1}->{emails} = $3 || '';
$data->{$1}->{flag} =
( ( defined $4 ) && ( $4 == 0 ) ) ? 0 : ( $4 || '' );
$data->{$1}->{pass_change} = $5 || '';
$data->{$1}->{flag_change} = $6 || '';
}
}
}
use Data:umper;
print Data:umper->Dump( [$data] );
__DATA__
AllPresent:hjliEO35kCgwI:[email protected]:1:23232:24324
LastMissing:CyL92g3OKi.jM:[email protected]:1:2323
FlagZero:CyL92g3OKi.jM:[email protected]:0:23232
OnlyFlag:ZuqpLZ7AxHBvw[email protected]:0
RestMissing:ZuqpLZ7AxHBvw:[email protected]
-------------------------
Please note - only first two fields are must fields, rest may be
missing from lines. first is - username, second is encrypted
password, third is email, fourth is flag to force user to change
password(0-pass change is not required, 1-user must change pass),
fifth- the last time password changed epoch time, sixth- time of
change of flag (some times flag is changed by admins of the system).
thanks in advance