mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-15 16:38:54 +00:00

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@313349 c90b9560-bf6c-de11-be94-00142212c4b1
150 lines
5.4 KiB
XML
150 lines
5.4 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<chapter xml:id="faq.passwords" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
<title>Safe Password Hashing</title>
|
|
<titleabbrev>Password Hashing</titleabbrev>
|
|
|
|
<para>
|
|
This section explains the reasons behind using hashing functions
|
|
to secure passwords, as well as how to do so effectively.
|
|
</para>
|
|
|
|
<qandaset>
|
|
<qandaentry xml:id="faq.passwords.hashing">
|
|
<question>
|
|
<para>
|
|
Why should I hash passwords supplied by users of my application?
|
|
</para>
|
|
</question>
|
|
<answer>
|
|
<para>
|
|
Password hashing is one of the most basic security considerations that
|
|
must be made when designing any application that accepts passwords
|
|
from users. Without hashing, any passwords that are stored in your
|
|
application's database can be stolen if the database is compromised, and
|
|
then immediately used to compromise not only your application, but also
|
|
the accounts of your users on other services, if they do not use
|
|
unique passwords.
|
|
</para>
|
|
<para>
|
|
By applying a hashing algorithm to your user's passwords before storing
|
|
them in your database, you make it implausible for any attacker to
|
|
determine the original password, while still being able to compare
|
|
the resulting hash to the original password in the future.
|
|
</para>
|
|
<para>
|
|
It is important to note, however, that hashing passwords only protects
|
|
them from being compromised in your data store, but does not necessarily
|
|
protect them from being intercepted by malicious code injected into your
|
|
application itself.
|
|
</para>
|
|
</answer>
|
|
</qandaentry>
|
|
<qandaentry xml:id="faq.passwords.fasthash">
|
|
<question>
|
|
<para>
|
|
Why are common hashing functions such as <function>md5</function> and
|
|
<function>sha1</function> unsuitable for passwords?
|
|
</para>
|
|
</question>
|
|
<answer>
|
|
<para>
|
|
Hashing algorithms such as MD5, SHA1 and SHA256 are designed to be
|
|
very fast and efficient. With modern techniques and computer equipment,
|
|
it has become trivial to "brute force" the output of these algorithms,
|
|
in order to determine the original input.
|
|
</para>
|
|
<para>
|
|
Because of how quickly a modern computer can "reverse" these hashing
|
|
algorithms, many security professionals strongly suggest against
|
|
their use for password hashing.
|
|
</para>
|
|
</answer>
|
|
</qandaentry>
|
|
<qandaentry xml:id="faq.passwords.bestpractice">
|
|
<question>
|
|
<para>
|
|
How should I hash my passwords, if the common hash functions are
|
|
not suitable?
|
|
</para>
|
|
</question>
|
|
<answer>
|
|
<para>
|
|
When hashing passwords, the two most important considerations are the
|
|
computational expense, and the salt. The more computationally expensive
|
|
the hashing algorithm, the longer it will take to brute force its
|
|
output.
|
|
</para>
|
|
<para>
|
|
There are two functions that are bundled with PHP that can perform
|
|
hashing using a specified algorithm.
|
|
</para>
|
|
<para>
|
|
The first hashing function is <function>crypt</function>, which natively
|
|
supports several hashing algorithms. When using this function,
|
|
you are guaranteed that the algorithm you select is available, as PHP
|
|
contains native implementations of each supported algorithm, in case
|
|
one or more are not supported by your system.
|
|
</para>
|
|
<para>
|
|
The second hashing function is <function>hash</function>, which supports
|
|
many more algorithms and variants than <function>crypt</function>, but
|
|
does not support some algorithms that <function>crypt</function> does.
|
|
The Hash extension is bundled with PHP, but can be disabled during
|
|
compile-time, so it is not guaranteed to be available, while
|
|
<function>crypt</function> is, being in the PHP core.
|
|
</para>
|
|
<para>
|
|
The suggested algorithm to use when hashing passwords is Blowfish, as it
|
|
is significantly more computationally expensive than MD5 or SHA1, while
|
|
still being scalable.
|
|
</para>
|
|
</answer>
|
|
</qandaentry>
|
|
<qandaentry xml:id="faq.passwords.salt">
|
|
<question>
|
|
<para>
|
|
What is a salt?
|
|
</para>
|
|
</question>
|
|
<answer>
|
|
<para>
|
|
A cryptographic salt is data which is applied during the hashing process
|
|
in order to eliminate the possibility of the output being looked up
|
|
in a list of pre-calculated pairs of hashes and their input, known as
|
|
a rainbow table.
|
|
</para>
|
|
<para>
|
|
In more simple terms, a salt is a bit of additional data which makes
|
|
your hashes significantly more difficult to crack. There are a number of
|
|
services online which provide extensive lists of pre-computed hashes, as
|
|
well as the original input for those hashes. The use of a salt makes it
|
|
implausible or impossible to find the resulting hash in one of these
|
|
lists.
|
|
</para>
|
|
</answer>
|
|
</qandaentry>
|
|
</qandaset>
|
|
|
|
</chapter>
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|