ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl.net
perl.net
Re: Making Linux User Password using perl
by $Bill Luebkert other posts by this author
Jun 22 2006 3:47AM messages near this date
view in the new Beta List Site
Re: Making Linux User Password using perl | Re: Making Linux User Password using perl
FRAMEWORK Vikasumit wrote:

>  Hi,
>   
>  Code i send previously is quite similar to yours its that you generate
>  salt from password or from time stamp,
>  But when I try this code in windows machine i got password as string
>  with out salt embeded in it
>   
>  where as in linux password saved as $1$somesalt$<password>
>  but it runs perfectly underlinux ...why is it so

When I run my example, I get:
encrypted passwd = 'U8CyANaZ6ztro'
encrypted passwd = 'U8CyANaZ6ztro'

What do you get  ?

Use this fixed example code:

use strict;
use warnings;

my $chk_only = 0;
my @legal_enc = ('.', '/', '0'..'9', 'A'..'Z', 'a'..'z'); # legal encrypted chrs
my $plainpasswd = shift || 'fubar';        # get commandline arg for password

my $crypted_passwd = crypt_passwd ($plainpasswd);
print "encrypted passwd = '$crypted_passwd'\n";

my $enc_passwd = $crypted_passwd;

$chk_only = 1;
$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;

}

__END__
_______________________________________________
Perl.NET mailing list
Perl.NET@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Vikasumit
$Bill Luebkert
Vikasumit
$Bill Luebkert
Vikasumit

Privacy Policy | Email Opt-out | Feedback | Syndication
© 2004 ActiveState, a division of Sophos All rights reserved