Gossamer Forum
Home : Products : DBMan : Customization :

Can you help me weed through this bit of Perl code?

Quote Reply
Can you help me weed through this bit of Perl code?
 I found this code in the FAQ under email user after signup:

Code:
my ($message,$userid, $pw, $view, $add, $del, $mod, $mem, $admin, $email, $password);

# Check to make sure userid is ok, pw ok, and userid is unique.
unless ((length($in{'userid'}) >= 3) and (length($in{'userid'}) <= 12) and ($in{'userid'} =~ /^[a-zA-Z0-9]+$/)) {
$message = ''Invalid userid: $in{'userid'}. Must only contain only letters and be less then 12 and greater then 3 characters.'';
}

unless ($in{'email'} =~ /.+\@.+\..+/) {
$message = ''Invalid email address format: '$in{'email'}'.'';
}

open (PASSWD, ''<$auth_pw_file'') || &cgierr(''unable to open password file. Reason: $!\n'');
@passwds = ;
close PASSWD;
foreach $pass (@passwds) { # Go through each pass and see if we match..
next if ($pass =~ /^$/); # Skip blank lines.
next if ($pass =~ /^#/); # Skip Comment lines.
chomp ($pass);
($userid, $pw, $view, $add, $del, $mod, $admin, $email) = split (/:/, $pass);
if (lc($in{'userid'}) eq lc($userid)) {
$message = ''userid already exists. Please try another.
'';
}
if (lc($in{'email'}) eq lc($email)) {
$message .= ''email address already exists.'';
}
}
if ($message) {
&html_signup_form ($message);
return;
}

$in{'pw'} = &generate_password;
$in{'email'} = lc($in{'email'});
# Add the userid into the file with signup permissions.
open (PASS, ''>>$auth_pw_file'') or &cgierr (''unable to open: $auth_pw_file.\nReason: $!'');
if ($db_use_flock) {
flock(PASS, 2) or &cgierr(''unable to get exclusive lock on $auth_pw_file.\nReason: $!'');
}
srand( time() ^ ($$ + ($$ << 15)) ); # Seed Random Number
my @salt_chars = ('A' .. 'Z', 0 .. 9, 'a' .. 'z', '.', '/');
my $salt = join '', @salt_chars[rand 64, rand 64];
my $encrypted = crypt($in{'pw'}, $salt);
my $permissions = join ('':'', @auth_signup_permissions);
print PASS ''$in{'userid'}:$encrypted:$permissions:$in{'email'}\n'';
close PASS;

But the only thing I need out of this is the part that opens the pass file to get the password to include in the email. I have no idea what half of this stuff means. I assume that it starts with the OPEN PASS line, but i'm not sure what after that because it looks like alot of checking going on in there also. I am in need of this code to email the user after they fill out the signup form AND add their user record via the users.db add form where they supply their email address.
Can someone tell me what needs to come out this bit of code to do what I need? BTW, this code to print the email is in my add_success sub and not the signup_success. Thanks!
Quote Reply
Re: [wdu2002] Can you help me weed through this bit of Perl code? In reply to
Bumping up, hoping someone can help Smile
Quote Reply
Re: [wdu2002] Can you help me weed through this bit of Perl code? In reply to
I understand you want to mail the password to the new user. However, doing that from the password_file will be pretty useless. The password in the file is encrypted, and noone can decrypt it, so there's no point in mailing it to the user.

If you want to mail the unencrypted password, just mail the value of $in{'pw'}.
kellner