Forum Moderators: coopster

Message Too Old, No Replies

user login php

         

ycliuwz

5:15 am on May 12, 2005 (gmt 0)

10+ Year Member



hi,
could anyone help provide me with examples of.
reading from a .txt file and comparing username and password to that entered in a login form.
and then redirecting to a specific page for each user logged in. oh and, how can i write date into the existing file with new userdata.
example

file.txt
--------
user1:pwd1
user2:pwd2
//add new user data
newUser:pwd

would really appreciate any kinda help i can get. thanks

IamStang

11:33 am on May 12, 2005 (gmt 0)

10+ Year Member



I dont have time to go into details of writing to text files this morning (have to get ready for work), but thought I would take a minute to ask a question.

Is this something for use on a server that can be accessed from the web? If so, I would advise you against storing username/passwords in a *.txt file. You can be as careful as you want, but if someone should stumble upon your *.txt file, they would have access to all your user/pass info. Basically, this method is one of the most insecure you could use.

If no database is available to you, atleast store the user/pass in an .htpasswd (if you have a low number of members). Still not a great deal of security, but leaps and bounds better than a *.txt file as most servers are set up to deny access to .htpasswd files.

Just my 2 cents.

mcibor

2:58 pm on May 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To read a file:
<?$file = @fopen("url/filename.txt", "r") or die("Could not open the file");
while(!eof($file)) $line = trim(fgets($file));
fclose($file);?>

to write to the file:
<?$file = @fopen("url/filename.txt", "w") or die("Disk space not accessible");

$data = date("Y-m-d");//YYYY-MM-DD (a mysql format)
fwrite("user_name:password_hash ".$data, $file);
fclose($file);?>


To get hash of a pass simply md5("password")
However much better way is to use db for that
If you want to know more about logins just do a search on google or www.hotscripts.com or write here and I'll help
Michal Cibor

ycliuwz

4:59 am on May 13, 2005 (gmt 0)

10+ Year Member



thanks mcibor, would really appreciate if u can help.
actaully i'm just trying to implement a simple login site. reading from a file that stores user and password data in the format provided earlier.
i think i know how to read the file just checking against the user input for username and password is wat puzzles me.
reading from file using foreach( ); and comparing is it ok?
once authentication is valid, user is redirected to their specific site. how can i do this? i've also been doing research on user logins and have found stuff like sessions and cookies? how are they used? thanks

jatar_k

3:54 pm on May 13, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



try this thread
PHP User Authentication and Passwords [webmasterworld.com] from our PHP Library [webmasterworld.com], lots of good stuff in there.

That one uses mysql but the premise is the same, instead of db queries you would be opening and reading your file.

ycliuwz

2:52 pm on May 14, 2005 (gmt 0)

10+ Year Member



Hi,
was wondering is it possible for me to get login info of user from a html page and pass the values over to a .php to carry out the authentication?
$username = post[%user]

is it something like the above?
any more info i can get on login authentication via php and for reading and writing file...
boy, this is so confusing. :(

jatar_k

3:32 pm on May 14, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if your form had the text elements named username and password

you could them access them in the script where they post to using

$_POST['username']
and
$_POST['password']