in reply to How do I encrypt an Unix password?
Here is some code you could use to take a plain text password, and encrypt it using a string. All/much of this code was taken from the first camel book:
Hopefully, that will get you started. However, you should look into a better way then this to do it, I just happened to have this code laying around :-)
-Eric
Update: Camel 3 suggests another way to generate a salt -- simply do this:
This works, however, I don't believe it to be incredibly secure. It first creates what's called a salt, and uses feeds that into the crypt function. Also, since this came from camel 1, be sure to add in the "my" statements where appropriate :-)# Generate a Salt $fullname = "Users Name"; $now = time; ($pert1, $pert2) = unpack("C2", "$fullname"); $week = $now / (60*60*24*7) + $pert1 + $pert2; $salt = ($week % 64) + ($now % 64); $salt = sprintf("%lx", $salt); # Use crypt to encrypt our password $passwd = crypt($password, $salt);
Hopefully, that will get you started. However, you should look into a better way then this to do it, I just happened to have this code laying around :-)
-Eric
Update: Camel 3 suggests another way to generate a salt -- simply do this:
I think that looks much nicer :-) That'll give you the encrypted password in a string. All you need to do then is figure out how to do the actual password update. Perhaps there is a system call for this? If not, you could always pipe it into the UNIX passwd command :-) HTHmy $salt = join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand + 64]; my $passwd = crypt($password, $salt);
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: How do I encrypt an Unix password?
by Abigail (Deacon) on Jun 27, 2001 at 03:18 UTC | |
by andreychek (Parson) on Jun 27, 2001 at 05:51 UTC | |
by Anonymous Monk on Jun 27, 2001 at 14:33 UTC |
In Section
Seekers of Perl Wisdom