Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

To register or not 2

by eoin (Monk)
on Dec 31, 2002 at 20:28 UTC ( #223446=perlquestion: print w/replies, xml ) Need Help??
eoin has asked for the wisdom of the Perl Monks concerning the following question:

OK, I've gone through the code a few times and can't find the problem. Its probably some stupid mistake or other but I can't get it.
Heres the code
use strict; use diagnostics; use warnings; use CGI; my $q = new CGI; my $user_name = $q->param('user_name'); my $gender = $q->param('gender'); my $real_name = $q->param('real_name'); my $city = $q->param('city'); my $country = $q->param('country'); my $email = $q->param('email'); my $confirmemail = $q->param('confirmemail'); my $mm = $q->param('birthmm'); my $dd = $q->param('birthdd'); my $yy = $q->param('birthyy'); my ($title, $body, $i, $s, @v, @c); #--------------------------------------------------------------------- #START OF MAIN PROGRAM #--------------------------------------------------------------------- my ($password) = &password(5); my $dateofbirth = ("$dd/$mm/$yy"); my @info = ($user_name, $password, $email, $gender, $real_name, $dateo +fbirth, $city, $country); open(USRNF,"pass") or die "Couldn't find user file.\n"; if ($email ne $confirmemail){ ($title, $body) = &email_invalid();} elsif (&check_user_email($user_name,$email) eq "good"){ ($title, $body) = &good(@info);} else { ($title, $body) = &check_user_email($user_name,$email); } print qq(Content-type: text/html\n <html> <head><title>$title</title></head> $body </html>); #--------------------------------------------------------------------- #END OF MAIN PROGRAM:BEGINING OF VERIFICATION #--------------------------------------------------------------------- sub email_invalid { my $title = "Email's do not match!!"; my $body = q(<body bgcolor="black" text="red"> <h3>Your e-mail doesn't match.</h3><br><br> <h2>Please click on your browsers back button and try again.</h2></a>< +hr> </body>); return ($title, $body); } #--------------------------------------------------------------------- sub check_user_email{ while(<USRNF>){ chomp; my $user = @_; my $email = @_; my (@userinfo) = split(/\t/, $_); if ( ($userinfo[0] ne $user) && ($userinfo[2] ne $email) ){ return "good"; } elsif ( $userinfo[0] eq $user ){ my $title = "User name already in use.!"; my $body = q(<body bgcolor="black" text="red"> <h3>The username $user is already in use.</h3><br><br> <h2>Please click on your browser's back button and try a different +one.</h2></a><hr> </body>); return ($title, $body); } else { my $title = "Account already activated.!"; my $body = q(<body bgcolor="black" text="red"> <h3>Our records show that you already have a valid account.</h3><br +><br> <h2>If you wish to create another one you must first delete the old + one.<br> </h2><h3>Please email me<a href="mailto:eoinmurphy\@dubl"> here</a> to edit any account info. <hr> </body>); return ($title, $body); close(USRNF); } } #--------------------------------------------------------------------- sub good{ my @info = @_; my $title = "Registration successful!"; my $body = q(<body> <h1>Registration Confirmation</h1> <hr> <p>Dear , $real_name</p> <p>Thank you for registering with us. You have supplied us with the following information:</p> <blockquote> <p><strong>Real name:</strong>\t$real_name <br> <strong>Username:</strong>\t$user_name <br> <strong>Password:</strong>\t$password <br> <strong>E-mail:</strong>\t$email <br> <strong>Date of Birth:</strong>\t$dateofbirth <br> <strong>City:</strong>\t$city <br> <strong>Country:</strong>\t$country <br> </p> </blockquote> <p>If any of this information is incorrect, please email me <a href="mailto:eoinmurphy\">here</a> to change it. I reserve the right to delete any user if he\she use this account for illegal purposes.</p> <blockquote> <blockquote> <blockquote> <p>Sincerely,</p> <p><em>Webmaster, Eoin.</em></p> </blockquote> </blockquote> </blockquote> <hr> <h5>You may return to the feedback form by using the <em>Back</em> button in your browser.</h5> <h5>Revised: <!--webbot bot="TimeStamp" startspan s-type="EDITED" s-format="%B %d, %Y" -->December 31, 2002<!--webbot bot="TimeStamp" i-checksum="39470" endspan -->.</h5> </body>); open(USRNF,">>pass") or die "Couldn't find user file.\n"; printf USRNF "$info[0] $info[1] $info[2] $info[3]. $in +fo[4] $info[5] $info[6] $info[7]"; close(USRNF); return($title, $body); } sub password{ $s = @_; srand($s ^ time); @c=split(/ */, "bcdfghjklmnpqrstvwxyz"); @v=split(/ */, "aeiou"); for($i = 1; $i <= 4; $i += 1) { my $password = print $c[int(rand(20))], $v[int(rand(5))] } }}
Feel free to help..
P.s. Happy New Year - 4.

Edit by tye to add READMORE

Replies are listed 'Best First'.
Re: To register or not 2
by jdporter (Canon) on Dec 31, 2002 at 20:45 UTC
    I haven't looked at the rest of your code, but your password subroutine is completely hosed.

    Please take a look at the responses you got to your other question, "To register or not (part 2)", and especially my response.


    The 6th Rule of Perl Club is -- There is no Rule #6.

Re: To register or not 2
by Sifmole (Chaplain) on Dec 31, 2002 at 20:42 UTC
    What is the problem? it would make it easier for us to help you.

    could someone explain why this got voted down? I wanted to help the guy but he didn't say what the problem was. I wanted to help but wanted to be told what the individual was looking for help with?

Re: To register or not 2
by Sifmole (Chaplain) on Dec 31, 2002 at 20:47 UTC
    Proper indentation might solve your problem, check out the ending curly braces on sub check_user_email
Re: To register or not (2)!!!
by ides (Deacon) on Dec 31, 2002 at 20:39 UTC

    You'll probably get more help if you let us know what the "problem" you are having is. Any error messages you are receiving, etc.

    Frank Wiles <>
      ...this is what I was about to say. Short of grabbing the whole program and setting up a test environment (which may not be that onerous), there's not even a clue here about what the program doesn't do right.

      So eoin if you can give us a hint about what isn't working right, perhaps someone can suggest an answer to the problem.

      In the meantime, try running the program in the debugger (invoke it with your input parameters on the command-line) and stepping through to what you consider to be the trouble spot. With the program stopped at that point, inspect the current value of your most important variables.

      Also, consider adding a section that hard-codes the input parameters for your testing purposes. By that I mean you could comment out the section that looks like this:

      my $user_name = $q->param('user_name'); my $gender = $q->param('gender'); my $real_name = $q->param('real_name');
      ...and retool it like this:
      =deadcode # production version my $user_name = $q->param('user_name'); my $gender = $q->param('gender'); my $real_name = $q->param('real_name'); =cut # test version my $user_name = "Mary"; my $gender = "Queen"; my $real_name = "She Who Must Be Obeyed";
      ...while you're testing, it's better to have a static set of input values, and even better if you don't have to provide them by hand each test run.

      Probably the most common problem I've seen with new CGI programs is that they haven't been tested fully the way we test other (command-line) programs. So be sure that it runs from the command-line and with the same permissions that the web server will have when the program is invoked in a CGI environment.

      Good luck, and bring more details about your program for additional help.

      update: Somebody apparently doesn't like the use of fake POD to comment out code?

      ...All the world looks like -well- all the world, when your hammer is Perl.

Re: To register or not 2
by eoin (Monk) on Jan 08, 2003 at 22:30 UTC
    Sorry, I forgot all about this question
    because after I posted it the solution came
    to me and I got it all working. Thanks for
    all your input.

    P.s. You'll be happy to know I've given up
    on the password generator above. Its to easy
    to crack. thanks especially to agentv, Sifmole and jdporter.
    All the Best, Eoin...

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://223446]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2018-03-21 19:35 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (270 votes). Check out past polls.