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:
# 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);
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 :-)
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:
my $salt = join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand
+ 64];
my $passwd = crypt($password, $salt);
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 :-) HTH
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.