Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

What the others said :)

Separate the HTML output from the logic: this code has the main effect of returning a userid, and the side effect of outputing the HTML header. At some point, you won't want to do the two things together.

Why not return undef, or '' as the not logged in value? I hope those will never match a valid userid, and also allows you to write:

my $userid=getuserid or castigate_user;
. Similarly, $exact_file can be treated the same way.

Use if as a statement modifier, rather than as a test in it's own right, then the code becomes more linear, and easier to read:

sub get_userid { my $member_dir = "../../Members/"; my $member_file ="memberslist.cgi"; return undef unless my %cookies = fetch CGI::Cookie; return undef unless $cookies{'UserName'}; return undef unless $cookies{'Password'}; my $id = $cookies{'UserName'}->value; my $password = $cookies{'Password'}->value; my $exact_file; $file = "$member_dir/$member_file"; open (FH, "< $file") or die "Could not open $file: $!"; while (<FH>){ chomp; my ($login, $junk_file) = split(/|!!|/); if ($login eq $id) { $exact_file=$junk_file; last; } } close FH; return undef unless $exact_file; $file ="$member_dir/$exact_file.cgi"; open (FH, "< $file") or die "Could not open $file"; my @user_list=(<FH>, <FH>); close FH; return undef unless $user_list[0] eq $id and $user_list[1] eq $password; return $id; }

Finally, do you really need to have an arbitarilly named password file for every single user? Why not just store the password directly in the members.cgi file?


In reply to Re: UBB find user id code by tommyw
in thread UBB find user id code by LeGo

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-19 21:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found