Switch to full style
Python Technology Tutorials Written By Members.
Post a reply

hashing in python

Mon Aug 27, 2012 12:21 am

Hash is a fixed bit length data that changes with the data input, hashes are used for security reasons, for example in case of user registration process, the password value is saved in a hashed form to the database while in login step the checking for password validation is done by comparing the hashes forms and not the original password input, by this manner it saves the passwords from being stolen by database administrator or any hacker. Hashing algorithms are one way encryption, in python we use the hashlib module which supports many algorithms MD4, MD5, SHA-1, SHA-2, etc, following is an example for hashing in python:


python code
import hashlib


## For algorithms have functions
print 'SHA-224: ',hashlib.sha224("codemiles").hexdigest()
print 'SHA-256: ',hashlib.sha256("codemiles").hexdigest()
print 'MD5: ',hashlib.md5("codemiles").hexdigest()
print 'MD4: ',hashlib.md4("codemiles").hexdigest()
print 'SHA-1: ',hashlib.sha1("codemiles").hexdigest()


## For algorithms have no functions ( Creating objects)
myHashAlg = hashlib.new('ripemd160');
myHashAlg.update('codemiles')
print 'RIPEMD-160: ',myHashAlg.hexdigest()

## Checking if the character case make a different.?
if hashlib.sha1("code").hexdigest() == hashlib.sha1("CODE").hexdigest():
print "NO"
else:
print "YES"




Post a reply
  Related Posts  to : hashing in python
 how to use GeoIP with Python     -  
 Python Module for MySQL     -  
 Reading email in Python     -  
 How to read and write to CSV file from python     -  
 exception handling try and catch in Python     -  
 usage of SQLite database from Python     -  
 Python Training from Certified Experts (ap2v.com)     -  
 Build Linear Regression in Python - Supervised Learning     -  

Topic Tags

Python, Python Algorithms