[Tutor] hashlib problems

Rance Hall ranceh at gmail.com
Fri Sep 10 20:00:15 CEST 2010


Im wanting to use the builtin hashlib functions to encrypt passwords
before storing them in a database.

According to documentation on the python.org site it should be as simple as

import hashlib

hashname = hashlib.sha234  (or whatever other hash method you want
like md5 or whatever)

hashname.update(b"test")  the b is for byte since the documentation
states that hashlib does not accept strings

hashname.hexdigest() or digest() will give you the hash encrypted
value.  (hexdigest will encode the output in hex for use in email and
string db storage)


My problem is that hashname.update results in a:

AttributeError:  'built_in_function_or_method' object has no attribute 'update'

I get this error in python 2 and python 3

I get it on multiple operating systems, so I dont understand whats
going wrong.  Either there is a bug in the module hashlib, or the
module changed and the docs don't keep up.

Either way I can not encrypt the password of my project for new users
till I figure out whats going on.

Your help much appreciated.

Rance


More information about the Tutor mailing list