Hi Monks,

A little while ago i posted a script that i wrote to take input from a form for you all to look at and comment on.
I think most of you came to the conclusion that the script was totaly insecure.
So, i've taken it back to base and re-wrote the whole thing.

Would you be able to take a look at it again for me, and tell me if it can be improved?
#!/usr/bin/perl -wT use CGI; use strict; # Set Variables my $w = new CGI; my $ip = $ENV{'REMOTE_ADDR'}; my $message = ""; my $found_err = ""; my $filenum = time.int rand 1000000; # Grab Input From Form my $username = $w->param('username'); my $domain = $w->param('domain'); my $email = $w->param('email'); my $service = $w->param('service'); my $conditions = $w->param('conditions'); # Begin Sanitising Input if ($username !~ /^[A-Za-z][-.\w]{2,29}$/) { $message = $message."<p>Error With Username. Please Retry</p>\ +n"; $found_err = 1; } if ($domain !~ m/^a.com|c.com|f.com|h.net|ho.com| |i.com|k.com|o.com|s.com|x.com$/) { $message = $message."<p>Error With Domain. Contact Support</p> +\n"; $found_err = 1; } if ($email !~ /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9] +)+$/i) { $message = $message."<p>Error With E-Mail Address. Please Retry</p +>\n"; $found_err = 1; } if ($service !~ m/^Yes|No$/) { $message = $message."<p>Error With Service. Contact Support</p +>\n"; $found_err = 1; } if ($conditions !~ m/^Yes$/) { $message = $message."<p>Please Accept The Terms And Conditions +</p>\n"; $found_err = 1; } if ($found_err) { &PrintError; } # Dump User Data To File open (LOGFILE, ">>/var/log/accounts/$filenum") or die $!; print LOGFILE "$username,$domain,$email,$service,$ip\n"; close (LOGFILE); # Display Html Completion print "Content-type: text/html\n\n"; print "Blah Blah, All Done\n"; # Display Error Messages sub PrintError { print "Content-type: text/html\n\n"; print $message; exit 0; return 1; }
Also note, that i am not too bothered about the e-mail address validation.
Thanks

In reply to Peruse my code... by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.