Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

server access prompt  & account registration

Posted on 1997-04-24
12
Medium Priority
?
153 Views
Last Modified: 2013-12-25
Alright, I have a cgi i made but i don't know how to keep people from using the same name. What is the coding for my script to check the password file for the name entered and tell if it is already in use. This is what i have :                open(PASSWD,">>$file");
      @lines = <PASSWD>;      
      ($c_uname,$passwd) = split(/:/,@lines);    
      if ($FORM{'uname'} eq $c_uname) {      
      &error('c_name');
      exit;
      }
0
Comment
Question by:Shadow041997
  • 8
  • 2
  • 2
12 Comments
 

Author Comment

by:Shadow041997
ID: 1827934
Edited text of question
0
 

Author Comment

by:Shadow041997
ID: 1827935
Edited text of question
0
 

Author Comment

by:Shadow041997
ID: 1827936
Edited text of question
0
How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

 

Author Comment

by:Shadow041997
ID: 1827937
Adjusted points to 210
0
 
LVL 2

Expert Comment

by:Voodoo
ID: 1827938
You've read in the whole file, but you now need to go through each element of the @lines array one by one. I'll add the code, once I've locked the question!
0
 
LVL 2

Expert Comment

by:Voodoo
ID: 1827939
Ok, now that you have read in the file, you now need to step through the @lines array, element by element, until one of two conditions occur. You find a successful match, or you reach the end of the array. Once either instance occurs, you can then break out of the loop. The following should do the trick.

-->8--

@lines = <PASSWD>;
$index = 0;        # To access @lines array

# Loop until we exceed number of elements within array
while ($index <= $#lines) {
  # auto increment $index
  ($c_uname,$passwd) = split(/:/,$lines[$index++]);

  # If name matches...
  if ($FORM{'uname'} eq $c_uname) {
    &error('c_name');
    exit;
  }
}

# If it gets here, then no match was found...

-->8--

Hope this helps...
0
 

Author Comment

by:Shadow041997
ID: 1827940
It does nothing when i enter the same name again, just gives the usual output.
0
 

Author Comment

by:Shadow041997
ID: 1827941
This is the script i have made, but i can't seem to get it to check the names already given in the password file.
#!/usr/local/bin/perl
###########################################################################

$file = '/users/yarkn/.htpp';
# Done
#############################################################################

# Parse Form Contents
&parse_form;

# Password Registry
&pass_reg;

# Return HTML Page or Redirect User
&return_html;


sub parse_form {

   if ($ENV{'REQUEST_METHOD'} eq 'GET') {
      # Split the name-value pairs
      @pairs = split(/&/, $ENV{'QUERY_STRING'});
   }
   elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
      # Get the input
      read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
 
      # Split the name-value pairs
      @pairs = split(/&/, $buffer);
   }
   

   foreach $pair (@pairs) {
      ($name, $value) = split(/=/, $pair);
 
      $name =~ tr/+/ /;
      $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

      $value =~ tr/+/ /;
      $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

      $value =~ s/<!--(.|\n)*-->//g;


         if ($FORM{$name} && ($value)) {
          $FORM{$name} = "$FORM{$name}, $value";
       }
         elsif ($value) {
            $FORM{$name} = $value;
         }
     }
   }


sub pass_reg {
     
   
if (!($FORM{'passwd1'} eq $FORM{'passwd2'})) {
      &return_html;
   }    
     
      open(PASSWD,">>$file");
      @lines = <PASSWD>;
      $new_uname = $FORM{'uname'} ;

      $index = 0; # To access @lines array

      # Loop until we exceed number of elements within array
      while ($index <= $lines) {
      # auto increment $index
      ($c_uname,$passwd) = split(/:/,$lines[$index++]);

      # If name matches...
      if ($FORM{'uname'} eq $c_uname) {
      &error('c_name');
      exit;
}
}



    $random = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
    $new_pass = crypt($FORM{'passwd1'} , $random);



    print PASSWD "$new_uname:$new_pass\n";
    close(PASSWD);
    &return_html;
    exit;
}
sub return_html {

print "Content-type: text/html \n\n";
print "<html><body bgcolor='#000000' text='#ffffff'></body>\n";
print "<center> Your Password is \"$FORM{'passwd1'}\". Your Username Is \n";
print "\"$FORM{'uname'}\".\n\n";
print "</html>\n";

}

sub error {
         
   ($error,@error_fields) = @_;

   print "Content-type: text/html\n\n";

  if ($error eq 'c_name') {

  print "<html><body bgcolor='#000000' text='#ffffff'></body>\n";
  print "<center> That Name Has Already been Chosen</html>\n";
 
  exit;
 
}
0
 
LVL 2

Accepted Solution

by:
n3mtr earned 420 total points
ID: 1827942
Your trying to read the file in append mode; you can't do that.(">>file") You need to open it for read mode(file) then close it and open it for append mode.  Or you could experiment with the read write mode(+>file) and the seek command.
0
 

Author Comment

by:Shadow041997
ID: 1827943
But what about the part that reads what variable should i use for this   ($c_uname,$passwd) = split(/:/,@lines);is that right ?
0
 
LVL 2

Expert Comment

by:n3mtr
ID: 1827944
It looks like voodoo's code should work, but you forgot to put in the pound sign in the while loop. $#lines will give you the total count of lines; that is what you want.  You have $lines.
I would have done it a different way, but it looks like it should work.
0
 

Author Comment

by:Shadow041997
ID: 1827945
I got my code tto work, thanks to everybody who gave me answers. I want to give voodoo and n3mtr the split of the points for all the help, but i can't so n3mtr gets the points.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question