Comics Page: Login

% if ($mesg) {
<% $mesg %>


% }

Login:
Password:

Forget your password?

<%init> my ($dbh, $sth, $mesg); $mesg = $ARGS{mesg}; $dbh = $m->comp('m/connect'); if ($ARGS{action} eq 'Mail password') { if (length($ARGS{user})) { $sth = $dbh->prepare( 'select email, password from user where user = ?'); $sth->execute($ARGS{user}); my ($email, $password) = $sth->fetchrow_array; if (defined $email) { open(MAIL, '|-') || exec('/usr/sbin/sendmail', $email); print MAIL < To: $email Subject: Your password Your user information is: user: $ARGS{user} pass: $password Login at: http://bushong.net/comics/login.html Enjoy! EOF close(MAIL); $mesg = 'Mail sent'; } else { $mesg = "No registered user with the login '$ARGS{user}'"; } } else { $mesg = 'Please enter a username to mail the password for'; } } elsif ($ARGS{action} eq 'Create account') { $m->comp('/m/redirect', 'create_account.html'); } elsif ($ARGS{action} eq 'logout') { my $user = $m->comp('m/get_user'); if (defined $user) { $dbh->do('delete from session where user = ' . $dbh->quote($user)); $r->headers_out->add('Set-cookie' => CGI::Cookie->new(-name => 'mason_id', -value => 0, -expires => '-1M')); } } else { ## action eq 'Login' or nothing if ($ARGS{user} && $ARGS{password}) { $sth = $dbh->prepare('select user from user where user = ? and password = ?'); $sth->execute($ARGS{user}, $ARGS{password}); my $ref = $sth->fetchall_arrayref; if (@$ref == 1) { ## user $m->comp('m/login', $ARGS{user}, 'index.html'); } else { $mesg = "Bad password for user: $ARGS{user}"; } } else { $mesg = 'Please enter a valid user and password'; } } $dbh->disconnect;