Now that we have that cleared up, lets get into some md5 encoding. Python offers a method pretty similar to PHP when it comes to md5. Simply include the hashlib library and you're good to go. Lets see how it would be done in PHP first.
$string = 'hello world';And here is the equivalent in Python.
$encoded_string = md5($string);
import hashlibObviously, the import belongs at the top of your file, but you should know that. One key thing to keep in mind that hashlib is new in Python 2.5. In older versions, you would use md5.
string = 'hello world'
encoded_string = hashlib.md5(string).hexdigest()
Remember, simply using md5 does not mean a string will be secure. Don't forget to use a salt! If you don't know what that is, you can try reading something like this, or google it.

If you don't know what a salt is, or even if you do, you probably shouldn't be implementing a user authentication feature. Just use someone else's well tested one.
ReplyDeleteYou should also be wary of MD5 - use SHA1 which is available in PHP, and Python through hashlib.
ReplyDelete