Search code examples
pythonpython-3.xpython-3.7md5hashlib

How to convert php md5(sha1(time())) in python3?


am new in python..

usually I do this in PHP md5(sha1(time())) and it convert something like: 017df9435b048f86ac28a274543ac46df5e20e0ecff32123a58287

Now how to do it in python3?

I've tried importing hashlib print(hashlib.md5(int(round(time.time() * 1)))) but not good results.

Can somebody help me? Thank you in advance.


Solution

  • It does not return same value as

    md5(sha1(time()))
    

    for same time because php functions md5 and sha1 return somebecausely different things than python3 functions hashlib.sha1 hashlib.md5, but following code might be what you want:

    import hashlib,time
    print(hashlib.md5(hashlib.sha1(str(int(round(time.time()))).encode()).hexdigest().encode()).hexdigest())