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: Intermediate:
check un/pw in a flatfile db

 



blubudda
stranger

Sep 27, 2001, 9:05 AM

Post #1 of 2 (601 views)
check un/pw in a flatfile db Can't Post

I am storing user name / password data in a flat file database. What is the best way to query the un / pw from the flatfile via a www page when the user is logging in? Thanks ya'll



S_Shrum
User

Sep 30, 2001, 12:59 AM

Post #2 of 2 (590 views)
Re: check un/pw in a flatfile db [In reply to] Can't Post

You could code a script yourself to get the user's input (via CGI-LIB), open/parse the datafile, and compare the entries to the user input, like this basic pseudo-code ( assumes comma delimited database with fields: USER NAME,PASSWORD )


Code
# push contents of db into multi-dim array 
0pen ( DB, "mypath\myfilename.dat" ) or die "unable to open";
while ( <DB> ) {
push @users, [ split(/\,/, $_) ];
close( DB );

# go thru each row and compare against user input
for $i ( 0..$#users ) {
if ( $users[$i][0] eq USERNAME ) {
if ( $users[$i][1] eq PASSWORD ) {
AUTHORIZE & REDIRECT TO CONTENT
} else {
REDIRECT TO FAILED.HTML
}
}
}
REDIRECT TO UNKNOWN_USER.HTML

You could even optimize this process by doing your comparisons WHILE you are loading the database (without putting them into an array first, I just like keeping things in arrays for data passing Smile).

Make sure you use some sort of authorization technique as once a person knows what the URL is to get access, they'll just bookmark it. I personally have not dealt with this as the stuff I have is pretty much open to everyone that can access the areas so it's no big deal for me.

Ask around here about authorization techniques and how to set them up.

Sean Shrum
sean@shrum.net
www.shrum.net

 
 


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

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