/
class.sha1.php
72 lines (70 loc) · 2.14 KB
/
class.sha1.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/**
* @package cryptography
*/
/**
* SHA1 is a cryptography class for hashing and comparing messages
* using the SHA1-Algorithm
*
* @since Symphony 2.3.1
* @see toolkit.Cryptography
* @deprecated This code is regarded as insecure and exists only for backwards-compatibility-purposes.
* It should not be used when writing new password-related features.
*/
class SHA1 extends Cryptography
{
/**
* Uses `SHA1` to create a hash based on some input
*
* @param string $input
* the string to be hashed
* @return string
* the hashed string
*/
public static function hash($input)
{
if (Symphony::Log()) {
Symphony::Log()->pushDeprecateWarningToLog('SHA1::hash()', 'PBKDF2::hash()', array(
'message-format' => __('The use of `%s` is strongly discouraged due to severe security flaws.'),
));
}
return sha1($input);
}
/**
* Uses `SHA1` to create a hash from the contents of a file
*
* @param string $input
* the file to be hashed
* @return string
* the hashed string
*/
public static function file($input)
{
if (Symphony::Log()) {
Symphony::Log()->pushDeprecateWarningToLog('SHA1::file()', 'PBKDF2::hash()', array(
'message-format' => __('The use of `%s` is strongly discouraged due to severe security flaws.'),
));
}
return sha1_file($input);
}
/**
* Compares a given hash with a cleantext password.
*
* @param string $input
* the cleartext password
* @param string $hash
* the hash the password should be checked against
* @param boolean $isHash
* @return boolean
* the result of the comparison
*/
public static function compare($input, $hash, $isHash = false)
{
if (Symphony::Log()) {
Symphony::Log()->pushDeprecateWarningToLog('SHA1::compare()', 'PBKDF2::compare()', array(
'message-format' => __('The use of `%s` is strongly discouraged due to severe security flaws.'),
));
}
return ($hash == self::hash($input));
}
}