Python function equivalent to Crypt in PHP

Asked

Viewed 87 times

0

I have a program in PHP that encrypts a password with the method crypt:

$crypt = '$1$/E0xe3/3$yPzJElk.aVSd5JoQTopDZ/';
if($crypt == crypt($_POST['key'],$crypt))

And with that I get the following hash of that password:

*$1$Mmd/1SKE$bE44ZNJgYXDjm10rUHC5L1*

I wanted to generate the same hash in Python, but I don’t know how.

The command:

 *cat /etc/login.defs | grep ^ENCRYPT_METHOD*

Returns (*ENCRYPT_METHOD SHA512*)

  • 1

    You can use the lib hashlib to generate hashs of the type he exemplified.

  • I was able to solve the problem by defining salt with crypt.crypt

1 answer

1


import crypt

hash = '$1$/E0xe3/3$yPzJElk.aVSd5JoQTopDZ/'
crypt.crypt('marcus.mann', hash)
  • Could add an explanation of your code?

  • It first defines what it wants to encrypt in the case of 'Marcus.mann' and soon after it defines the salt or "method" of encryption that will be used

Browser other questions tagged

You are not signed in. Login or sign up in order to post.