[Tutor] hashlib problems

Dave Angel davea at ieee.org
Fri Sep 10 21:10:20 CEST 2010



On 2:59 PM, Rance Hall wrote:
> 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)
>
You forgot the parentheses.  You also picked one that doesn't exist, so 
switch to sha256() or sha384().
> 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