Search code examples
pythonmongodbrestful-architectureeve

how to store values in mongodb in hashed format using python


I am developing a web API using EVE REST Framework it contains a table which holds password of the users. When i send a 'get' request to mongodb the password is displayed in visible format. Can anyone tell me how to store values in mongodb which is not in a readable format(hashed format).

Thanks in advance!!!


Solution

  • You can use the hashlib library in python. You can pick from whichever algorithms you like, using md5 will look something like this:

    import hashlib
    password = 'abc123'
    hash_object = hashlib.md5(password.encode())
    print(hash_object.hexdigest())
    >>>
    e99a18c428cb38d5f260853678922e03
    

    See the docs also, https://docs.python.org/2/library/hashlib.html