Questions tagged [crypt]

crypt() is Unix C library function used for hashing passwords. It is also found in PHP, Perl, Python and various other languages.

crypt(3) is a Unix C library function used for hashing passwords. The crypt() function takes in a password and an optional salt string (chosen randomly if not supplied), and calculates a cryptographic message digest based on them. The digest includes the salt used to generate it, so that, when the user re-enters their password, the digest can be recalculated and compared with the previously stored value.

Despite its name, the crypt(3) function cannot actually be used to encrypt data; the transformation it implements is deliberately non-reversible, so that its output cannot be decrypted to recover the original password.

The "traditional" hashing algorithm used by the original Unix crypt(3) was based on a modified version of the DES block cipher, and only supported passwords of up to 8 characters, with 7 bits per character, and a two-character salt with 6 bits per character. This algorithm is nowadays considered insecure due to its limited keyspace and high speed, which allow an attacker using modern computers to test all possible passwords by brute force in a relatively short time. Nonetheless, most crypt(3) implementations still include it for the sake of backwards compatibility.

Most modern crypt(3) implementations include various alternative hashing algorithms, which typically support arbitrarily long passphrases, longer salts and adjustable iteration counts to deliberately slow down the digest calculation for key stretching. One well known example of such an algorithm is , which is based on the Blowfish cipher.

Functions similar in name and purpose to (and possibly implemented by) the Unix crypt(3) function are also found in several high-level languages, including PHP, Perl and Python.

The crypt(3) function should not be confused with the Unix command line utility crypt(1), which is an obsolete and insecure file encryption utility. For a modern replacement, see .

553 questions
4
votes
2 answers

What is the difference between the bcrypt() and the crypt() methods?

I was wondering what is the difference between these? I was having a discussion with someone about the crypt method and he was talking about the bcrypt method but to me it sounded like they are the same methods. Thanks
baihu
  • 451
  • 1
  • 4
  • 16
4
votes
1 answer

Crypt() salt generation and password encryption, well executed?

these are some functions I am using for password encryption and password verification. Was wondering if this is a good way to handle it. I am using the codeigniter framework. This is the function to 'encrypt' : function crypt_pass( $input ){ …
Jursels
  • 173
  • 1
  • 3
  • 12
4
votes
1 answer

How to verify hash created with php-crypt in node.js

I must migrate my backend from php to node. We used php crypt (with default random salt) to hash the passwords. For instance, for the password 'd1692fab28b8a56527ae329b3d121c52', I have the following crypted pw in my base (depending if I used either…
Sebastien
  • 115
  • 9
4
votes
2 answers

What is the safest algorithm in Kohana's auth module?

I'd prefer to use the crypt function and use blowfish encryption, but the current implementation of this module uses the hash function, which doesn't offer this encryption method. So, what is the safest algorithm in Kohana's auth module? Would…
amgeex
  • 43
  • 4
4
votes
3 answers

Crypt function doesn't work when comparing string to hash

I'm using a pretty standard way of cookie login - I give the user two cookies, one with his username and the other with a randomly generated string plus a user-specific salt. This is what happens at…
sveti petar
  • 3,637
  • 13
  • 67
  • 144
4
votes
2 answers

PHP crypt producing different results

Okay i am sitting here since hours scratching my head at this issue and i cannot figure out what is wrong. I am trying to encrypt a password via a random salt with crypt but when i try to login the has is always wrong. Let me walk you through the…
Sepiksu
  • 41
  • 3
4
votes
1 answer

Why CRYPT_BLOWFISH in PHP is considered better, when it produces shorter hashes than SHA

Why CRYPT_BLOWFISH in PHP is considered better for password hashing, when it produces shorter hashes than CRYPT_SHA-256/512? Isn't it more possible to find another word that computes the same BLOWFISH hash, than SHA256/512 hash? Example hashes taken…
d-ph
  • 572
  • 4
  • 17
4
votes
1 answer

salted password hashes without saving the salt

I've got a mailserver which stores passwords for mailboxes in a mysql database with the following sql: ENCRYPT([PASSWORT], concat(_utf8"$1$", right(md5(rand()), 8), _utf8"$")) But there is no salt stored in the database. Now i need to build a…
4
votes
4 answers

What is Go's equivalent to Python's crypt.crypt?

I am currently playing around with an example from the book Violent Python. You can see my implementation here I am now trying to implement the same script in Go to compare performance, note I am completely new to Go. Opening the file and…
igniteflow
  • 8,404
  • 10
  • 38
  • 46
4
votes
2 answers

python, get encrypted user password from shadow

I'm trying to obtain the encrypted system user password in order to compare it with another sha512 encrypted one. I tried pwd, but it seems that this module does not deal with user passwords, or the used system is "too modern" for it (a debian…
ScotchAndSoda
  • 3,811
  • 4
  • 34
  • 38
3
votes
1 answer

Anybody seen a crypt(3) implementation in Javascript?

I'm looking for an implementation of crypt(3) in javascript. (Not a generic "crypt" algorithm, but the crypt(3) one used in /etc/shadow e.g. on Linux systems). Anybody seen one? With an open license? I'm a little worried about performance too: Would…
Peter V. Mørch
  • 13,830
  • 8
  • 69
  • 103
3
votes
2 answers

Is there an OpenCL implementation of the unix crypt(3) function?

I want to use the unix crypt function in an OpenCL program. Does something like that already exist or will I have to translate it on my own?
mae
  • 14,947
  • 8
  • 32
  • 47
3
votes
2 answers

Porting hashs from php's crypt() to python

I was wondering if there is a python cognate to PHP's crypt() function that performs in a similar way, generating a random salt and embedding it within the saved string. I have a table of hashed passwords that were created using the $5$ string key…
DeaconDesperado
  • 9,977
  • 9
  • 47
  • 77
3
votes
4 answers

crypt() not functioning as needed

I'm using crypt as follows: $pass = crypt($pass, 'd4'); for both insertion and validation of a password against a mysql table. Problem is that if the passwords are similar it generates a similar result. Is there an algorithm that guarantees…
user656925
3
votes
1 answer

How to check password on macOS?

The following C program can check the password of a user on Linux. But it does not work on macOS because some functions are Linux specific. Could anybody show me how to revise the program so that it works on macOS? #include #include…
user15502206