1

I am trying to find an equivalent function to UnixCrypt in Python for Windows. What I have found so far is that python does provide a crypt function, but it is only for Unix os. For Windows os, there are Cairnarvon's crypt.py, and passlib's des_crypt. So just as an example, to hash the password, you just have to pass the password and a salt (2-character string) to the functions:

from passlib import hash
import crypt as cryptC
pwd = "password"
salt = "JQ"
#Cairnarvon's crypt.py
print(cryptC.crypt(pwd,salt))
# passlib's des crypt
print(hash.des_crypt.encrypt(pwd,salt=salt))

Both functions above output the same hash:

JQMuyS6H.AGMo

However this does not prove that they are giving out the same hash as UnixCrypt or Python's crypt. To confirm this, I will need a unix os, but I don't. Can someone kind enough to provide me the hash from UnixCrypt using the password and salt in the above example? Thanks.

Community
  • 1
  • 1
pangyuteng
  • 1,749
  • 14
  • 29
  • 1
    `>>> import crypt >>> crypt.crypt("password", "JQ") 'JQMuyS6H.AGMo' >>> import sys >>> sys.platform 'linux'` – matsjoyce Sep 24 '14 at 16:31
  • Came back to this post 6 year later only to find I upvoted your reply only, but have not yet thanked you. so Thank you for your time for posting the above! Will accept the answer if you post it as answer. :D – pangyuteng Jul 02 '20 at 03:32
  • 1
    Yikes, this is a blast from the past! I've posted an answer as requested, although I don't expect this to be useful for many other people. – matsjoyce Jul 03 '20 at 20:43
  • Indeed this isn't the kind of question that the site is for IMO. Anyway, about the question: when you do import crypt as cryptC; cryptC.crypt(...) you are just using crypt.crypt, just like I would in Linux. Or am I missing something? By the way, crypt.crypt will use a stronger algorithm if you omit the salt (and use the complete output of crypt as the salt when checking a password). – Bas Wijnen Jan 12 '21 at 10:53

1 Answers1

1

As requested:

Python 3.8.3 (default, May 17 2020, 18:15:42) 
[GCC 10.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import crypt
>>> crypt.crypt("password", "JQ")
'JQMuyS6H.AGMo'
$ uname -ampo
Linux matthew-laptop 5.7.6-arch1-1 #1 SMP PREEMPT Thu, 25 Jun 2020 00:14:47 +0000 x86_64 GNU/Linux

Also, if you have a choice of algorithm, I would recommend a newer and slower algorithm such as PBKDF2 or bcrypt.

matsjoyce
  • 5,744
  • 6
  • 31
  • 38