Click to See Complete Forum and Search --> : Login Page


lonogod
11-22-2005, 09:47 PM
Hello everyone. Can anyone tell me how to confirm information from a text file? I have a form where users make a user name and password that is then put in a flat text file. Now I need to confirm the user name and password from the text file. Can anyone explain this to me? Thanks.

lonogod

PS: I need for this to be CGI.

Jeff Mott
11-23-2005, 05:31 AM
Given how little we know of your exact situation, find the user/password pair from the inputted user name. Then compare the inputted password with the one in the DB. If it matches then you're all good. If not then show an error.

c0d3z3r0
11-23-2005, 08:33 AM
hi there! im having a problem with our signup page can somebody here help me???

below is the code thanks...



#!/usr/local/bin/perl
#
# This is a sample CGI program that displays a form where
# you should specify the account name, user's real name,
# password and mailbox type. After you click "Create" button
# it will connect to CGPro and create the account.
#
# Don't run it from the command shell if you don't know what you're doing.
#
# The CGPro's address and Postmaster login params should be
# defined manually in the script's text, see below.
#
#

my $CGServerAddress = "xxx.xxx.xxx.xxx";
my $PostmasterLogin = "postmaster";
my $PostmasterPassword = "********";

BEGIN
{
use FindBin qw($Bin);
use lib "$Bin";
}#This is for web server so it could find CLI.pm from the current directory

use strict;
use CLI;
use CGI qw(:standard);

print header; # Print "Context-type: text/html"

# print "<HTML>"
# print "<HEAD>User Creation Sample CGI</HEAD>"
# print "<BODY>"
print start_html("User Creation Sample CGI");

if($PostmasterPassword eq "") { # You didn't specify domain/login/password

errormsg("You have to modify the script file to specify the CGPro Server address and Postmaster password");

} elsif(param()) { # The form is already filled
# Read the parameters from the form
my $Account = param("account");
my $RealName = param("realname");
my $Password1 = param("password1");
my $Password2 = param("password2");
my $BoxType = param("boxtype");
my $RecoverPasswordAddr = param("recover");

if ($Account eq "") {
errormsg("No account name specified");
}
if ($Password1 eq "") {
errormsg("No password specified");
}
if ($Password1 ne $Password2) {
errormsg("Passwords do not match!");
}
my $cli = new CGP::CLI( { PeerAddr => $CGServerAddress,
PeerPort => 106,
login => $PostmasterLogin,
password => $PostmasterPassword } );
SecureLogin => 0
unless($cli) {
errormsg("Can't login to CGPro: ".$CGP::ERR_STRING);
last MAIN;
}

my $UserData;
@$UserData{'RealName'}=$RealName;
@$UserData{'Password'}=$Password1;
@$UserData{'RecoverPassword'}=$RecoverPasswordAddr if($RecoverPasswordAddr);

if($cli->CreateAccount(accountName => $Account,
accountType => $BoxType,
settings => $UserData)) {
print h1("Account created.");









print a({-href=>'CreateUserCGI.pl'},
'Create one more User<br>');
print a({-href=>"default.html?Username=$Account&Password=$Password1"},
'Open the created Account');

} else {
errormsg("Can't create '$Account' account: ".$cli->getErrMessage);
last MAIN;
}
$cli->Logout;

} else { # The form is empty
print h1("Create a user: "),hr();
print start_form();
print p("Account name: ",textfield("account"));
print p("Real name: ",textfield("realname"));
print p("Password: ",password_field("password1"));
print p("Password (again): ",password_field("password2"));
print p("Mailbox type: ",
popup_menu( "boxtype", ['TextMailbox','MultiMailbox','MailDirMailbox']));
print p("E-mail address to retrieve forgotten password: ",textfield("recover"));
print p(submit("Create"),reset("Clear"));
print end_form(),hr();
}
print end_html(); # print"</BODY></HTML>"

sub errormsg { #a procedure to output error message in HTML format and exit
my ($msg) = @_;
print h1("ERROR: $msg");
print a({-href=>'CreateUserCGI.pl'}, 'Create a User');
print end_html();
exit;
}

Nedals
11-23-2005, 02:33 PM
lonogod,

#!/usr/local/bin/perl

use strict;
use CGI;

my $q = CGI->new();
my $pwdfile = '/full-path-to/filename';
my $valid = 0;

open FIL, $pwdfile || die "Cannot open $pwdfile, $!";
while (<FIL>) { # step though the file entries
# Assumption:
# Data saved as "username:password" with non-encrypted passwords
my ($username,$password) = split(':',$_);
if (($username eq $q->param('username') && ($password eq $q->param('password')) {
$valid = 1;
last; ## found it, so exit loop
}
}
close(FIL);

if ($valid) {
print "Valid user\n";
} else {
print "User not in file\n";
}

c0d3z3r0
11-24-2005, 07:31 AM
do you want me to change the whole script instead? totally have no idea on what you have just posted!.. thanks... btw, do you want me to post the login.pl script?

Nedals
11-24-2005, 12:16 PM
My post is in response to lonogod's question. He was the one who, after all, started this thread.

I don't even know why you, c0d3z3r0, posted in this thread.

Nedals
11-24-2005, 12:29 PM
Follow up to c0d3z3r0....
I would recomend that you delete your post, replacing it with..
"Update: Deleted off-topic thread"
and re-post your question in a NEW thread.

Things get really confusing if topics are mixed in a single thread, as noted by your response.
.. totally have no idea on what you have just posted!..

gozarca2
12-11-2005, 12:42 PM
yeah c0d3z3r0, post another thread, i'm not sure what error you are seeing...what error message you getting. you could exit the script early and report what its done..standard debugging.