When you sign up for an account somewhere, some websites do not actually store your password in their databases. Instead, they will transform your password into something else using a cryptographic hashing algorithm.
After the password is transformed, it is then called a password hash. Whenever you try to login, the website will transform the password you tried using the same hashing algorithm and simply see if the password hashes are the same.
Create the python function that converts a given string into an md5 hash. The return value should be encoded in hexadecimal.
the function will turn “password” into “5f4dcc3b5aa765d61d8327deb882cf99”
We will use the
hashlib module to evoke the md5 function, but before we can turn any string into an md5 hash we need to make sure we have already encoded the string first. Finally, return the md5 hash in the hexadecimal format!
import hashlib def pass_hash(str): m = hashlib.md5(str.encode()) return m.hexdigest()
If you are using Python 3.x then you will need to use hashlib instead of the other python md5 hash’s library.