edatz
02-14-2009, 09:22 AM
Hi, I've got an old script that I use fine (nice and simple) where I can log in and do stuff. No problem at all.
However, it only allows me to use it and I would like to make it so more than one person can log in.
The login for the script is currently like this
# username and password
# How do I check username and password against a file instead of this?
$username = "aaa";
$password = "111";
When I log in with aaa and 111, it takes me to a sub:
sub checkUser {
if ($input{'username'} ne $username || $input{'password'} ne $password) {
print "ACCESS DENIED";
exit(0); #### Note-this exits to the rest of the script and it can be used
}
}
Every sub routine in the script has checkUser first - no login no use.
How can I make this so I can have more than one user?
I'm assuming a d simple file (users.txt) like this for the users;
aaa|111
bbb|111
ccc|111
I did try this but it had the total opposite effect:
sub checkUser {
$userfile = "users.txt";
open (UDB,"$userfile") || die("Cannot open $userfile");
@USF = <UDB>;
close (UDB);
foreach $usr (@USF) {
chomp;
($username,$password)=split(/\|/,$rec);
if ($input{'username'} ne $username || $input{'password'} ne $password) {
print "ACCESS DENIED";
exit(0); #### Note-this exits to the rest of the script and it can be used
}
}
}
Can someone help please?
Thank you
However, it only allows me to use it and I would like to make it so more than one person can log in.
The login for the script is currently like this
# username and password
# How do I check username and password against a file instead of this?
$username = "aaa";
$password = "111";
When I log in with aaa and 111, it takes me to a sub:
sub checkUser {
if ($input{'username'} ne $username || $input{'password'} ne $password) {
print "ACCESS DENIED";
exit(0); #### Note-this exits to the rest of the script and it can be used
}
}
Every sub routine in the script has checkUser first - no login no use.
How can I make this so I can have more than one user?
I'm assuming a d simple file (users.txt) like this for the users;
aaa|111
bbb|111
ccc|111
I did try this but it had the total opposite effect:
sub checkUser {
$userfile = "users.txt";
open (UDB,"$userfile") || die("Cannot open $userfile");
@USF = <UDB>;
close (UDB);
foreach $usr (@USF) {
chomp;
($username,$password)=split(/\|/,$rec);
if ($input{'username'} ne $username || $input{'password'} ne $password) {
print "ACCESS DENIED";
exit(0); #### Note-this exits to the rest of the script and it can be used
}
}
}
Can someone help please?
Thank you