Click to See Complete Forum and Search --> : Username/password retrival script
GurusGuru
08-19-2004, 01:06 AM
Does anyone have a username/password retrival script?
I have a flat text file xyz.log in the cgi-bin that contains the data delimited by '::'. The username and password are in 10 and 11th fields and the email ID in the 4th position
eg
Mr::Dan::Moris::xyz@abcde.com::Address::City::State::Code::Country::username::password::Duration
I need a stand alone script to retrive the username & password. If a person forgets his password a static page comes up forgot.htm in which he can mention either his username or email (2 separate fields) to retrive password. If the username or email is not in the database then another page comes up tryagain.htm stating to try again as username or email could not be found. If the username or email is found in the database then another page sent.htm comes up stating that the email has been sent with username and password.
silent11
08-19-2004, 11:06 AM
#!/usr/bin/perl
use strict;
use CGI ':standard';
my $found_email = 'no';
if ( param('username') ) # username value is sent via a form
{
for ( <DATA> )
{
my @line = split (/::/,$_);
if ( $line[9] eq param('username') )
{
send_password($line[3],$line[10]);
$found_email = 'yes';
}
}
send_error() if $found_email eq 'no';
}
sub send_password
{
# do what you want with the email and password
my ($email,$password) = @_;
print "$email, your password is $password.\n";
}
sub send_error
{
# do what you want if username not found in list.
print "param(username) wasn't found in our list.\n";
}
__DATA__
Mr::an::Moris::xyz@abcde.com::Addy::City::State::Code::Country::username1::9assword1::duration
Mr::an::Moris::xyz@abcde.com::Addy::City::State::Code::Country::username2::9assword2::duration
Mr::an::Moris::xyz@abcde.com::Addy::City::State::Code::Country::username3::9assword3::duration
silent11
08-19-2004, 11:08 AM
see attached
Originally posted by GurusGuru
Does anyone have a username/password retrival script?
I need a stand alone script to retrive the username & password. If a person forgets his password a static page comes up forgot.htm in which he can mention either his username or email (2 separate fields) to retrive password.
It seems that you want to be able to enter the username OR email to retrieve the password. That being the case, the script below should do. Just have a form with ONE textfield named retrieve and a submit button. The user can either enter his username OR email to retrieve his username & password. Also, you might need to adjust the path to sendmail. If your server doesn't support sendmail, the send_info subroutine will need to be reworked.
#!/usr/bin/perl
use strict;
use CGI qw/:standard/;
my @log;
my $y = 0;
print header;
if (param('retrieve')) {
open(LOG, 'xyz.log') || die $!;
while(<LOG>) {
@log = split(/::/, $_);
if (param('retrieve') eq $log[9] || param('retrieve') eq $log[3]) {
$y = 1;
&send_info;
}
}
close(LOG) || die $!;
}
print 'USERNAME OR EMAIL NOT FOUND !' if $y != 1;
sub send_info {
open(MAIL, "|/usr/sbin/sendmail -t") || die $!;
print MAIL qq`To: $log[3]
From: password_retrieval\@service.net
Subject: Login Information
username: $log[9]
password: $log[10]`;
close(MAIL) || die $!;
print 'YOUR USERNAME & PASSWORD HAVE BEEN EMAILED';
}
GurusGuru
08-20-2004, 06:22 AM
Getting the error - USERNAME OR EMAIL NOT FOUND
This is the form I am using to retrive.
<form method="POST" action="http://www.xyz.com/cgi-bin/forgotpass.pl">
<p><input type="text" name="Retrieve" size="20"><br>
<input type="submit" value="Retrieve"></p>
</form>
forgotpass.pl is the above script
Instead of 'USERNAME OR EMAIL NOT FOUND ! ' can a html page come up - tryagain.htm
and instead of 'YOUR USERNAME & PASSWORD HAVE BEEN EMAILED' - sent.htm
Hi, GurusGuru...
First of all, the name of the textfield must be all lower case, "retrieve" not Retrieve", to work as is.
Secondly, if you want static pages to replace the built-in ones I've used, then change these lines accordingly.
change this:
print 'USERNAME OR EMAIL NOT FOUND !' if $y != 1;
to this:
print redirect('http://www.domain.com/tryagain.htm') if $y != 1;
AND
change this:
print 'YOUR USERNAME & PASSWORD HAVE BEEN EMAILED';
to this:
print redirect('http://www.domain.com/sent.htm');
GurusGuru
08-20-2004, 10:36 AM
Thanks. Got it to work. I was making a mistake
1::2::3::email::5::6
I was putting the email as log[4] whereas it should be log[3]
print redirect('http://www.domain.com/tryagain.htm') if $y != 1;
and
print redirect('http://www.domain.com/sent.htm');
are giving the following errors:
Status: 302 Moved location: http://www.domain.com/tryagain.htm
Status: 302 Moved location: http://www.domain.com/sent.htm
Can I also define the target frame for tryagain.htm and sent.htm
OK, as far as the target, yes, you can set that aspect in your form...
<form method="POST" action="http://www.xyz.com/cgi-bin/forgotpass.pl" target="_blank">
or
<form method="POST" action="http://www.xyz.com/cgi-bin/forgotpass.pl" target="frame_name">
...depending on how you wish to load the redirects...
...about the redirects:
remove this line:
print header;
GurusGuru
08-20-2004, 11:36 PM
Thanks CyCo. Everthing is working fine.
Originally posted by GurusGuru
Thanks CyCo. Everthing is working fine.
You're welcome. :)