Re: Making Linux User Password using perl
by $Bill Luebkert other posts by this author
Jun 22 2006 3:20AM messages near this date
view in the new Beta List Site
Making Linux User Password using perl
|
Re: Making Linux User Password using perl
FRAMEWORK Vikasumit wrote:
> Hi,
>
> I am writing a Perl Script that a user run to make linux user password
> style password ....
>
> I mean If a user type "password"
>
> I can save this password such that I just replace it in /etc/shadow
> password coulmn and his password changes.
>
> I can generate password using PHP crypt function but not through perl
> please help...
This belongs in win32-users group.
Untested in this form:
use strict;
use warnings;
my $chk_only = 0;
my $plainpasswd = shift; # get commandline arg for password
my $crypted_passwd = crypt_passwd ($plainpasswd);
print "encrypted passwd = '$crypted_passwd'\n";
exit;
sub crypt_passwd { # $crypted_passwd = crypt_passwd ($plainpasswd [, $salt]);
my $passwd = shift;
my $salt;
# if salt supplied
if (defined $_[0]) {
$salt = substr $_[0], 0, 2; # get first 2 chars for salt
# else create a salt using time, pid and rand
} else {
if ($chk_only) {
$salt = substr $enc_passwd, 0, 2; # get first 2 for salt
} else {
my $tmp = (time + $$) % 65536;
srand ($tmp);
$salt = $legal_enc[sprintf "%u", rand (@legal_enc)];
$salt .= $legal_enc[sprintf "%u", rand (@legal_enc)];
}
}
my $new_passwd = crypt ($passwd, $salt);
return $new_passwd;
}
_______________________________________________
Perl.NET mailing list
Perl.NET@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Vikasumit
$Bill Luebkert
Vikasumit
$Bill Luebkert
Vikasumit
|