Total members 11894 |It is currently Fri Nov 22, 2024 3:27 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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"




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
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     -  
 exception handling try and catch in Python     -  
 usage of SQLite database from Python     -  
 How to read and write to CSV file from python     -  
 Python Training from Certified Experts (ap2v.com)     -  
 Build Linear Regression in Python - Supervised Learning     -  



Topic Tags

Python, Python Algorithms
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com