String Encryption |
| Written by phpecho.com | |||
If you're building a user system, or any other method of authentication, this is definitely a necessity for you. You can't just store raw passwords, that's unsafe and unmoral - keep your user's privacy at hand, and encrypt those passwords. There are two foolproof ways of encrypting strings. md5(), and sha1(). First on the list is md5(). This function returns a 128bit string of randomly assigned characters, and is probably the most common function used from encryption today. Every string has a unique set of characters, that always stays the same. Here is an example of md5's usage, in encrypting the word 'string'. $string = 'string'; $hash = md5($string); It word return $hash as this: b45cffe084dd3d20d928bee85e7b0f21 The next encryption method is sha1(). SHA stands for Secure Hash Algorithm, and is equally as safe as md5(). This function returns a 160bit string of assigned characters to the specified string, that also always stays the same. An example of sha1's usage is below. $string = 'string'; $hash = sha1($string); This would return $hash as the following string: ecb252044b5ea0f679ee78ec1a12904739e2904d You can also get experimental, and combine both methods, to create something like the following. $string = 'string'; $hash = sha1(md5($string)); This would return $hash as the following: 68fe1f51772a8e68ad92cc929da539ff411149fe That's all in another tutorial from phpecho.com! Thanks for reading!
|