|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
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! |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
||||
|
||||
|
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. |
|
#5
|
|||
|
|||
|
Hello Mickalo
Its working fine. Thanks much Keshav |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > Help me to retrieve data from a flat file |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|