Total members 11621 |It is currently Wed Mar 29, 2017 7:56 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka

All times are UTC [ DST ]



  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"




Author:
Mastermind
User avatar Posts: 2704
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : hashing in python
 how to use GeoIP with Python     -  
 Python Module for MySQL     -  
 Reading email in Python     -  
 usage of SQLite database from Python     -  
 How to read and write to CSV file from python     -  
 exception handling try and catch in Python     -  

All times are UTC [ DST ]



Topic Tags

Python Algorithms






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team