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: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

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved