A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://php.net/manual/en/function.crypt.php below:

PHP: crypt - Manual

crypt

(PHP 4, PHP 5, PHP 7, PHP 8)

cryptOne-way string hashing

Warning

This function is not (yet) binary safe!

Description

Prior to PHP 8.0.0, the salt parameter was optional. However, crypt() creates a weak hash without the salt, and raises an E_NOTICE error without it. Make sure to specify a strong enough salt for better security.

password_hash() uses a strong hash, generates a strong salt, and applies proper rounds automatically. password_hash() is a simple crypt() wrapper and compatible with existing password hashes. Use of password_hash() is encouraged.

The hash type is triggered by the salt argument. If no salt is provided, PHP will auto-generate either a standard two character (DES) salt, or a twelve character (MD5), depending on the availability of MD5 crypt(). PHP sets a constant named CRYPT_SALT_LENGTH which indicates the longest valid salt allowed by the available hashes.

The standard DES-based crypt() returns the salt as the first two characters of the output. It also only uses the first eight characters of string, so longer strings that start with the same eight characters will generate the same result (when the same salt is used).

The following hash types are supported:

Parameters
string

The string to be hashed.

Caution

Using the CRYPT_BLOWFISH algorithm, will result in the string parameter being truncated to a maximum length of 72 bytes.

salt

A salt string to base the hashing on. If not provided, the behaviour is defined by the algorithm implementation and can lead to unexpected results.

Return Values

Returns the hashed string or a string that is shorter than 13 characters and is guaranteed to differ from the salt on failure.

Warning

When validating passwords, a string comparison function that isn't vulnerable to timing attacks should be used to compare the output of crypt() to the previously known hash. PHP provides hash_equals() for this purpose.

Changelog Version Description 8.0.0 The salt is no longer optional. Examples

Example #1 crypt() examples

<?php
$user_input
= 'rasmuslerdorf';
$hashed_password = '$6$rounds=1000000$NJy4rIPjpOaU$0ACEYGg/aKCY3v8O8AfyiO7CTfZQ8/W231Qfh2tRLmfdvFD6XfHk12u6hMr9cYIA4hnpjLNSTRtUwYr9km9Ij/';// Validate an existing crypt() hash in a way that is compatible with non-PHP software.
if (hash_equals($hashed_password, crypt($user_input, $hashed_password))) {
echo
"Password verified!";
}
?>
Notes

Note: There is no decrypt function, since crypt() uses a one-way algorithm.

See Also remi at php dot net

6 months ago

The crypt_gensalt function (from the xpass extension) makes usage of this function much easier, ex:

<?php

$salt

= crypt_gensalt(CRYPT_PREFIX_BLOWFISH, 10);
$hash = crypt($secret, $salt);


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4