LeGo has asked for the wisdom of the Perl Monks concerning the following question:
Well I am going to post some code. I have a subroutine that will either return the users name or a message that will say the something to the fact "NOTLOGGEDIN" as I am assuming that no one will use that user name. If they do I will adjust.
If you could check out the code and see if there are some things that you would change. Do note that this does run... if you see something that will functionally not work agian please let me know.
Basically the way that UBB works (exclusively describing for this example), is that once a user post, the users name and password are stored in cookies. I grab these. Then I check to see if this person is an actual user. If not I return NOTLOGGEDIN. UBB stores the users info in a file, I get this file name from memberslist.cgi by splitting then getting user names and file names. If they match I then open the one that coincides with the cookie $id. This file has the user name and the user password. I compare these, if they match I return the user name, else NOTLOGGEDIN.#!d:\perl\bin\perl.exe -w use strict; use CGI; use CGI::Cookie; my $user = &get_userid; print "<p>whoa whoa whao $user"; sub get_userid{ print "Content-type:text/html\n\n"; ##################################################### #Here are global things that might need to be changed #these will be required from another file... had to #add for coding post though ##################################################### #Where are the Members directories? my $member_dir = "../../Members/"; #what is the name of the file that list the members my $member_file ="memberslist.cgi"; ##################################################### my $file; #the concat file, used in opens my $exact_file = "noneyet"; #this is the exact member file my @user_list; #this is the users info file holds #real cookie with user name my $login; #compares variable to id my $junk_file; #junk variable my $id; #here is the cookie id my $password; #this is the password from the cookie my %cookies; #hash to hold cookies my $nli = "NOTLOGGEDIN";#my not logged in value to return if(%cookies = fetch CGI::Cookie){ if($cookies{'UserName'}){ $id = $cookies{'UserName'}->value; }else{ return "$nli"; } if($cookies{'Password'}){ $password = $cookies{'Password'}->value; }else{ return "$nli"; } }else{ return "$nli"; } $file = "$member_dir/$member_file"; open (FH, "$file") or die "Could not open $file: $!"; while(<FH>){ chomp; ($login, $junk_file) = split(/\|\!\!\|/); if ($login eq $id){ $exact_file ="$junk_file"; } } close FH; if ($exact_file eq "noneyet"){ return "$nli"; } $file ="$member_dir/$exact_file.cgi"; open (FH, "$file") or die "Could not open $file"; while(<FH>){ chomp; push @user_list, $_; } close FH; if($user_list[0] eq $id){ if($user_list[1] eq $password){ return "$user_list[0]"; }else{ return "$nli"; } }else{ return "$nli"; } }
It appears that this is very simple. I could expand to NOTAUSER, FAKEPASSWORD, but for my purpose now I don't need that functionality. Maybe the next version will have that.
I understand this code could hinder the speed of the program becuase it does not break when the user is found. I have tried break but get an use strict not allowed error. Could someone help speed this up for me?
Those are the types of things I am looking for help with. Much thanks. :)while(<FH>){ chomp; ($login, $junk_file) = split(/\|\!\!\|/); if ($login eq $id){ $exact_file ="$junk_file"; } }
LeGo
LeGo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: UBB find user id code
by chromatic (Archbishop) on Oct 09, 2001 at 23:58 UTC | |
|
Re: UBB find user id code
by arturo (Vicar) on Oct 10, 2001 at 00:08 UTC | |
|
Re: UBB find user id code
by tommyw (Hermit) on Oct 10, 2001 at 00:50 UTC | |
by LeGo (Chaplain) on Oct 10, 2001 at 01:14 UTC | |
by tommyw (Hermit) on Oct 10, 2001 at 01:57 UTC |