Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old February 7th, 2001, 06:29 PM
Keshav Keshav is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2000
Location: Chennai, Tamilnadu, India
Posts: 19 Keshav User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hello

I am using a login page(html) with username and password. I have stored the different usernames and passwords in a flat file (e.g xyz.txt). i have used tabspace in between username and password. and there will be single username and password in each line. i am getting the value of username and password from the form and comparing it with the flat file. It is not working properly. It says wrong username or password even i had given the correct username and password which was in flat file. I have given the code below. Can anyone help me?
-----------------------------------------------------------

#! /usr/bin/perl
use CGI;
print"content-type:text/html\n\n";
my $action = new CGI;
my $login = $action->param('username');
my $password = $action->param('password');
my $file = "address.txt";
open(INFILE, $file) or die " The file $file could not be found\n";

while(<INFILE>){
my $row = $_;
chomp($row);
my @currentrow = ();
@currentrow = split(/\t/, $row);
$var = crypt("$password", xx);
if ($login eq $currentrow[0] && $var eq $currentrow[1])
{
print $currentrow[0];
print $currentrow[1];
print "It is working\n";
exit;
}
else
{
print $currentrow[0];
print $currentrow[1];
print "You have entered wrong username or password\n";
exit;
}
}
-----------------------------------------------------------
Flat file address.txt
-----------------------------------------------------------
john john123
steve steve123
david davis

-----------------------------------------------------------

Thanks in Advance
Keshav

Reply With Quote
  #2  
Old February 7th, 2001, 06:45 PM
mickalo's Avatar
mickalo mickalo is offline
Ole` Timer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2000
Location: N.W. Iowa
Posts: 469 mickalo User rank is Private First Class (20 - 50 Reputation Level)mickalo User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 5 h 19 sec
Reputation Power: 8
Send a message via AIM to mickalo Send a message via MSN to mickalo
In your code you have:
Code:
$var = crypt("$password", xx); 
if ($login eq $currentrow[0] && $var eq $currentrow[1])


You've encrypted the password they have entered into the form, then you check the encrypted password agaisnt the password in the address.txt file, but from your sample address.txt file, the password is not encryted, so you won't get a match.

Mickalo
__________________

Thunder Rain Internet Publishing

Custom Programming & Database development
Providing Personal/Business
Internet Solutions that work!

Reply With Quote
  #3  
Old February 7th, 2001, 06:53 PM
Keshav Keshav is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2000
Location: Chennai, Tamilnadu, India
Posts: 19 Keshav User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
reply

Hello Mr. Micalo
Thanx for ur immediate response. Its working fine. But it is checking with the first row only. I need to check all the rows. Tell me what to do.

Thanx
Keshav

Reply With Quote
  #4  
Old February 7th, 2001, 07:25 PM
mickalo's Avatar
mickalo mickalo is offline
Ole` Timer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2000
Location: N.W. Iowa
Posts: 469 mickalo User rank is Private First Class (20 - 50 Reputation Level)mickalo User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 5 h 19 sec
Reputation Power: 8
Send a message via AIM to mickalo Send a message via MSN to mickalo
I would do this a slightly different way:
=============================================
$found = undef;
open(INFILE, $file) or die " The file $file could not be found\n";
@data = <INFILE>;
close (INFILE);

LOOP: foreach $row (@data) {
chomp $row;
@currentrow = split(/\t/, $row);
$var = crypt("$password", xx);
if ($login eq $currentrow[0] && $var eq $currentrow[1]) {
$found = 1;
last LOOP;
}
}
if (defined($found)) {
print $currentrow[0];
print $currentrow[1];
print "It is working\n";
exit;
}
else
{
print "You have entered wrong username or password\n";
print "Login: $login Password: $password\n";
exit;
}
==============================

When you need to loop thru a file to check for a specific match such as a username, password,..etc. It usually works better if you don't use while(<FILEHANDER>), use the foreach loop method. Try the code and see if this works for you.

Reply With Quote
  #5  
Old February 7th, 2001, 07:39 PM
Keshav Keshav is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2000
Location: Chennai, Tamilnadu, India
Posts: 19 Keshav User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hello Mickalo
Its working fine.
Thanks much
Keshav

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Help me to retrieve data from a flat file


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway