Using PHP Encryption for Login Authentication | 2 | WebReference

Using PHP Encryption for Login Authentication | 2


[prev]

Using PHP Encryption for Login Authentication [con't]

The Editor

The editor is where all the text processing takes place. It is made up of a form that presents the user with a text area. This area enables a user to manipulate text at will. Below is the editor script code:

The code begins by opening up a session and including the global.php file:

Then we get the contents of the diary for the user. We do this by using the user's ID to search for the contents in the contents database:

When we find the information that we want, we store the text in a variable called $txt:

Otherwise, we show an error message:

If the user clicks on the encrypt button, then we start the text-encryption process:

First we set the key and input, which in this case is stored in the $confession variable:

Then we set some constant:

Finally we encrypt the text:

And close the module:

Now we update the database simply by running the UPDATE SQL:

As for the file-based storage, we simply open the file, read its contents and then store it in a variable:

If the user clicks on the exit button, we need to store the information to file. So, we simply open up a file and then replace the current text with the new text:

We encrypt the text that was sent by the form:

Then we store the contents in the file by using the fwrite() function:

We print a message to show the outcome of the writing process:

Conclusion

That's it for this three-part series on encryption:

  1. Encryption Techniques for Your PHP Development
  2. Implementing One-way Encryption in PHP
  3. Using PHP Encryption for Login Authentication

You can improve this program even further by using encryption algorithms such as AES or Rijndael. They will make your data more secure. Happy coding!

Original: June 1, 2010


[prev]