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
55
votes
2 answers

Given a linux username and a password how can I test if it is a valid account?

So my question is straight forward given a linux username and a password how can I test if it is a valid account?
smit
  • 959
  • 1
  • 9
  • 20
32
votes
1 answer

Where 2x prefix are used in BCrypt?

The question is the same title, Where $2x$ is used in BCrypt? The following scenario is right? We have a set of passwords that hashed with $2a$ prefix already, when the Server PHP version was earlier 5.3.7. Now we upgraded the PHP to 5.3.7+, now we…
msoa
  • 1,339
  • 3
  • 14
  • 33
30
votes
4 answers

Why does crypt/blowfish generate the same hash with two different salts?

This question has to do with PHP's implementation of crypt(). For this question, the first 7 characters of the salt are not counted, so a salt '$2a$07$a' would be said to have a length of 1, as it is only 1 character of salt and seven characters of…
Dereleased
  • 9,939
  • 3
  • 35
  • 51
27
votes
2 answers

How to create and store password hashes with Blowfish in PHP

1) How do you create secure Blowfish hashes of passwords with crypt()? $hash = crypt('somePassword', '$2a$07$nGYCCmhrzjrgdcxjH$'); 1a) What is the significance of "$2a"? Does it just indicate that the Blowfish algorithm should be used? 1b) What is…
user479911
18
votes
1 answer

Crypt for password hashing. Blowfish produces weird output

I am having a bit little bit of trouble understanding php's crypt function. My PHP version is 5.4.7. I want to use crypt to store salted passwords in the database, because as far as I am told, developers who use md5 to hash passwords are to be…
Anpan
  • 1,146
  • 1
  • 10
  • 20
17
votes
3 answers

What to use for password hashing? Any reason not to use jBCrypt?

I'm planning to use jBCrypt for password hashing in a new web application, as it is supposed to be the best from what I've read. As I haven't used it before I'm looking into if there is any reason not to use it. I have this: I haven't found it in…
user14070
17
votes
4 answers

strcmp vs. == vs. === in PHP for checking hash equality

I'm using crypt() to hash passwords in PHP, and am trying to work out the safest way of testing equality of the resulting hash when performing password checks. There are three options that I can see: Option 1 - Double Equals function…
Polynomial
  • 27,674
  • 12
  • 80
  • 107
15
votes
1 answer

What is the correct format for a blowfish salt using PHP's crypt?

I have read the information provided on the PHP Manual Entry for crypt(), but I find myself still unsure of the format for a salt to trigger the Blowfish algorithm. According manual entry, I should use '$2$' or '$2a$' as the start of a 16 character…
Dereleased
  • 9,939
  • 3
  • 35
  • 51
14
votes
1 answer

Which hashing algorithm provides the longest output?

I was curious about which hashing method usable by PHP's crypt function provides the longest output, and also, if the length of the output was relative at the chance of their being a collision of two hashes.
SHH
  • 492
  • 1
  • 5
  • 13
13
votes
6 answers

Can an MD5 hash have ONLY numbers or ONLY letters in it?

I have been researching but I am clueless. I know that MD5 can have both numbers and letters but if I ever find a case where an MD5 has only numbers or only letters it breaks my script currently
Mark
  • 133
  • 1
  • 1
  • 5
13
votes
1 answer

hash() vs. crypt() function comparison

I'm currently implementing a login system. I want to store the password and the salt in a database. Now I found out that there is a hash() and a crypt() function which seems to do the same (valid for SHA512). hash() is newer and seems to support…
testing
  • 19,681
  • 50
  • 236
  • 417
12
votes
4 answers

undefined reference to `crypt'

I am using the below code that i found somewhere in the net and i am getting an error when i try to build it. The compilation is ok. Here is the error: /tmp/ccCnp11F.o: In function `main': crypt.c:(.text+0xf1): undefined reference to…
Stelios
  • 261
  • 1
  • 5
  • 14
11
votes
4 answers

What is the output length of PHP crypt()?

what's the output length of PHP crypt()? md5() output is 128 bits and produce a string with 32 chars, so in data base you put that in a char(32) column, what about the crypt()?
MTVS
  • 2,046
  • 5
  • 26
  • 37
10
votes
8 answers

Python crypt module -- what's the correct use of salts?

First, context: I'm trying to create a command-line-based tool (Linux) that requires login. Accounts on this tool have nothing to do with system-level accounts -- none of this looks at /etc/passwd. I am planning to store user accounts in a text file…
Schof
  • 6,329
  • 5
  • 28
  • 38
10
votes
1 answer

How to make Ubuntu's crypt(3) support Blowfish?

According to the crypt(3) manual, Blowfish (indicated by the $2a$ prefix) is one of the supported cypher methods: ID | Method ───────────────────────────────────────────────────────── 1 | MD5 2a | Blowfish (not in mainline glibc; added in some …
mae
  • 14,947
  • 8
  • 32
  • 47
1
2 3
36 37