Solved

server access prompt  & account registration

Posted on 1997-04-24
12
151 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

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 210 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

Linux Academy Android App Now Supports Chromecast

We have some fantastic news for our Android fans. We’re so excited to announce that the Linux Academy Android app is now available with Chromecast support. That’s right – simply download the latest update of the Linux Academy App and start casting your favorite course videos!

Question has a verified solution.

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

In this tutorial I will focus on how to use WhizBase as a tool for sending ICQ messages to ICQ. Here I will use a new technology in WhizBase, published in WhizBase 5.1 version. In this tutorial I will use 3 files, pager.wbsp for the processing, e…
I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

623 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