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

PHP crypt(pass, salt) alternative in Java - Blowfish algorithm

I'm using on php server function crypt like this: $hash = crypt($password, '$2y$10$' . $salt); It makes hash of password by Blowfish method. I'm looking for java equivalent for crypt password. I found this code, but I don't know where add $salt.…
Payne
  • 456
  • 6
  • 21
3
votes
4 answers

Algorithm behind MD5Crypt

I'm working with Subversion based on Windows and would like to write an easy utility in .NET for working with the Apache password file. I understand that it uses a function referred to as MD5Crypt, but I can't seem to find a description of the…
Lee
  • 18,529
  • 6
  • 58
  • 60
3
votes
3 answers

What field type should be used for passwords in MySQL when using PHP crypt()

Using PHP crypt() method I have a PHP script to store users encrypted passwords in MySQL database. What field type should I use to store the encrypted data?
Mona Coder
  • 6,212
  • 18
  • 66
  • 128
3
votes
3 answers

How to get salt from a password and use it to validate user?

I have read tons of questions and tutorials about encrypting a password, and while I've learned a lot, nowhere did I find an answer to this. I want to use crypt() for hashing a password that I will store on Database. I also know I need to use a salt…
Ant100
  • 403
  • 1
  • 8
  • 26
3
votes
1 answer

Ruby string#crypt in c# and php

I have a ruby client program that encrypts a password with string#crypt like so encrypted = password.crypt(SALT) # removing first two characters which actually are the salt for safety return encrypted[2, encrypted.size - 2] it then sends it…
Ryex
  • 31
  • 2
3
votes
1 answer

Blowfish Algorithm in PHP and iOS

I'm trying to encrypt a string the same way on a server in PHP as on an Objective-C on iOS. I've used PHP's crypt() function with the blowfish algorithm, but it takes two parameters: the string to encode and a salt. The Objective-C implementation I…
Nick C
  • 514
  • 3
  • 12
3
votes
3 answers

is it safe to store crypt() salt in database for password comparison

Forgive me guys, I am completely new to password security and encrypting... I am having problems comparing stored passwords that have been encrypted using php's crypt() function (using the blowfish hasing method) to a user's input. One way I have…
3
votes
1 answer

Different versions of PHP different results of crypt ()

Code: echo $a = 'stackoverflow'; echo '
'; echo $b = '$2a$10$bf57caf7e1fa23e4b975ab'; echo '
CRYPT:
'; echo crypt($a, $b); Results: PHP 5.2.5 stackoverflow $2a$10$bf57caf7e1fa23e4b975ab CRYPT: $2.LaeiP21fsQ PHP…
Kubol
  • 353
  • 2
  • 7
3
votes
1 answer

C crypt() not working correctly on md5 mode?

I'm using the crypt() function for the first time in c. I'm just running some initial tests, so none of this is actually going to be used, the constant salt value in particular. :) I run the following code: crypt(password, "$1$k7de83ka7"); From my…
dsw88
  • 4,400
  • 8
  • 37
  • 50
3
votes
3 answers

Zend_Auth_Adapter_DbTable and PHP crypt

I am hashing my passwords in a Zend php application using PHP crypt(). However, I can't think of a solution for using this hash with Zend_Auth_Adapter_DbTable. Assuming I have a password hash stored after being run with crypt()... //Salt and…
bristophocles
  • 143
  • 1
  • 14
3
votes
1 answer

Why is crypt() generating different results?

Crypt is generating different hashes with the same input data, and the [following] previously functional hash generator/check is no longer working for authenticating users: public static function blowfish($password, $storedpass = false) { //if…
KneeSkrap3r
  • 103
  • 9
3
votes
1 answer

Is this good use of crypt?

I'm upgrading my auth class, replacing md5 with crypt for storing passwords. Here's the approach I've taken: function crypt_pass($pass, $userID) { $salt = $userID .'usesomesillystringforsalt'; // min 22 alphanumerics, dynamic $method =…
designosis
  • 5,182
  • 1
  • 38
  • 57
2
votes
2 answers

PHP: crypt() function returns same string if base string has only slight variation

I'm having an issue using crypt. I'm rebuilding a site for a client. So there's a lot of inherited code from the previous version. I have to keep the sites original database in tact, so I have to be careful what I change code-wise. The previous…
LoneWolfPR
  • 3,978
  • 12
  • 48
  • 84
2
votes
2 answers

clarification for crypt SHA-512 algorithm (c#)

EDIT: Sorry I forgot to mention, I'm not using the implemented sha512 crypt because as far as I can tell it doesn't involve a salt value or a specified number of rounds to compute the hash with. Okay so I'm coding the sha-512 crypt in c# and I'm…
dollardime
  • 145
  • 11
2
votes
1 answer

Storing bcrypt hashes

According to PHP's doc, bcrypt salt are made of "$2a$", a two digit cost parameter, "$", and 22 digits from the alphabet "./0-9A-Za-z" So, if i use the crypt() function to hash my passwords, the resulting output include the first 7 chars…
geezmo
  • 161
  • 1
  • 3
  • 12