input data-encrypt password-write to flat file<

admin

Administrator
Staff member
I'm having a bit of a problem here, I'm trying to make a script that would allow me to store passowrds, e-mails, and password in a flat file. I'm new to using files in PHP, and using the crypt() function, so I'll need a bit of help.

Heres my code right now:


<?

$username=$_POST['username'];
$email=$_POST['email'];
$password = crypt("$_POST['password']");

$fp = fopen("users.txt","a");

$stringtowrite=$username."|".$email."|".$password;

fwrite($fp, $stringtowrite);

fclose($fp);

?>

It worked when I wasn't using encryption, but when I added the password encryption it wouldn't work.

Also, how do I create a line break so when someone inputs something else, it appears on the line below, all I'm getting now is:
username|password|emailusername|password|email

Any help would be appreciated.

ThanksFor the line break try this:

$stringtowrite=$username."|".$email."|".$password. "\n";

That should work I believe.
As for the crypt() part, not sure :(why have 2 password??

as for crypt, scoutt said in anothers post that it's better and easier to use md5() instead...

or if you use crypt, you have to provide a salt, if not, it will never be the same encryption for the same password!See this thread (<!-- m --><a class="postlink" href="http://www.htmlforums.com/showthread.php?s=&threadid=35288">http://www.htmlforums.com/showthread.ph ... adid=35288</a><!-- m -->).

What is a salt, and how is it used?Well, I'm using md5() now, so it is a lot easier for encryption. But, I still can't get a line break. Heres the code.



<?

$fp = fopen("users.txt","a");

$stringtowrite=$username."|".md5("$email")."|".md5("$password"). "\n";

fwrite($fp, $stringtowrite);

fclose($fp);

?>Deleted text.For a line break try to insert a carriage return character which is ASCII Decimal 13 or Hex 0D into the string.And how would I do that? (I don't know a thing about ASCII or Hex)Here, this variable (end of line) will do the CR job in PHP codes.

$eol = "\r\n";That did the job, thanks a lot!
 
Back
Top