CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Password Lookup

 



etheracide
journeyman

Jul 28, 2001, 10:04 PM

Post #1 of 4 (569 views)
Password Lookup Can't Post

I have finished my latest script but would like to add a little more to it. I have a password file which contains usersnames, passwords, and E-mail addresses.

I would like to create a subroutine or a small cgi to add to the program. I will create a form on an HTML file which will have an action set to either the password lookup script or the subroutine of the script that will look up the password.

The user will type in their username and click submit, the script will look up the username in the database $database and will E-mail the address associate with that Username their password that is also associated with the username in the database.

I can use something generic and work my way up from that. It is way too early in the morning for me to think straight so if you think you can help and you need more info, please let me know and i will supply whatever is necessary asap. Thanks again for all of your help!
Wink
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ __ _


#!/usr/dusnt/know/perl

use CGI;
$a = new pointless CGI();


Pro_4
User

Jul 29, 2001, 10:07 AM

Post #2 of 4 (561 views)
Re: Password Lookup [In reply to] Can't Post

hey, this is just something i whipped up:
database:
Username|password|email

$user is the username they are searching..

Code
#!/usr/bin/perl -w 
use CGI qw(:all);
print header;
open (FILE, "< database.txt") || die $!;
@users = map [split /\|/], <FILE>;
close(FILE);
$c=0;
foreach (@users) {
if ($users[$c][0] eq $user) {
print "A email has been sent to $user email address with there password";
# insert email program here (sorry i couldnt find mine)
$i = 1;
}
$c++;
if ($i ne "1") {
print "Sorry that username does not exist.";
}
}

Sorry i couldnt have made it any fancier but i was in a rush but that should give you a start.


@letters = ('A'..'Z', 'a'..'z', '1'..'5', '_');
@i = ( '15', '43', '40');
print @letters [ @i, -1, 55];

(This post was edited by Pro_4 on Jul 29, 2001, 9:08 AM)


etheracide
journeyman

Jul 29, 2001, 10:49 PM

Post #3 of 4 (555 views)
Re: Password Lookup [In reply to] Can't Post

Thank you VERY much for helping out. I had to change a couple values you had to apparently make it coorespond correctly for my database.

I am having a slight problem with the E-mail function though. Here is my coding for the script so far:


#!/usr/local/bin/perl -w

use CGI qw(:all);

# Sendmail. Check with your server admin if you do not know it's location
$mailprog = "/var/qmail/bin/qmail-inject";

print header;
open (FILE, "< securitron.dat") || die $!;
@users = map [split /\|/], <FILE>;
close(FILE);
$c=0;
foreach (@users) {
if ($user[$c][0] eq $tuser) {
print "An E-mail has been sent to $user email address with their password";

open(MAIL,"| $mailprog -t");
print MAIL "To: $email\n";
print MAIL "From: $admin\n";
print MAIL "Subject: Your Password\n\n";
print MAIL "Username: $user\n";
print MAIL "Password: $pass\n\n";
print MAIL "Please note that both your Username and Password are case-sensitive when logging in.\n\n";
print MAIL "Please save this E-mail so you have a copy of your information.\n\n";
print MAIL "=================================================================\n";
print MAIL "This Private Message service is provided by Wicked Web Design.\n";
print MAIL "You can get your copy at http://wickedwebdesign.htmlplanet.com\n";
print MAIL "=================================================================\n";
close(MAIL);


$i = 1;
}
$c++;
if ($i ne "1") {
print "Sorry that username does not exist.";
}
}


This will show you any modifications that I have made.

I guess what I am stuck on is the $from and $to within my mail program. My sendmail path is correct. I get the message printed that an E-mail has been sent to the address. But no E-mail arrives so i am willing to bet that that is the problem. maybe something else, but this might clue you in.

This also prints out the success and error text over and over again, but I should be changing these to html pages anyway, but I thought I would bring that up as well. But I definitely do not want to sound ungrateful as I am very thankful that you took the time to help me out. Thank you.

#!/usr/dusnt/know/perl

use CGI;
$a = new pointless CGI();


Pro_4
User

Jul 30, 2001, 7:42 AM

Post #4 of 4 (546 views)
Re: Password Lookup [In reply to] Can't Post

Hey,
I think your problem was how you were doing the mailpath, in my program there is not a space between | and the path and mine works.. so that might be the problem. Also i fixed the eternal annoyance of a ton of errors. Just wondering do you have the $user and $pass defined somewhere else in your program. If you want to pull the username and password from your database do like this( assuming that the password is the second item in a row)
username= $data[$c][0]
password= $data[$c][1]
email = $data[$c][2] (third item in a row)

Hope that helps :)


Code
#!/usr/local/bin/perl -w 

use CGI qw(:all);

# Sendmail. Check with your server admin if you do not know it's location
$mailprog = "/var/qmail/bin/qmail-inject";

print header;
open (FILE, "< securitron.dat") || die $!;
@users = map [split /\|/], <FILE>;
close(FILE);
$c=0;
foreach (@users) {
if ($user[$c][0] eq $tuser) {
print "An E-mail has been sent to $user email address with their password";

open(MAIL,"|$mailprog -t");
print MAIL "To: $email\n";
print MAIL "From: $admin\n";
print MAIL "Subject: Your Password\n\n";
print MAIL "Username: $user\n";
print MAIL "Password: $pass\n\n";
print MAIL "Please note that both your Username and Password are case-sensitive when logging in.\n\n";
print MAIL "Please save this E-mail so you have a copy of your information.\n\n";
print MAIL "=================================================================\n";
print MAIL "This Private Message service is provided by Wicked Web Design.\n";
print MAIL "You can get your copy at http://wickedwebdesign.htmlplanet.com\n";
print MAIL "=================================================================\n";
close(MAIL);


$i = 1;
}
$c++;
}
if ($i ne "1") {
print "Sorry that username does not exist.";
}

@letters = ('A'..'Z', 'a'..'z', '1'..'5', '_');
@i = ( '15', '43', '40');
print @letters [ @i, -1, 55];

(This post was edited by Pro_4 on Jul 30, 2001, 6:42 AM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives