ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilBasePasswordEncoder.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2014 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Services/Password/interfaces/interface.ilPasswordEncoder.php';
5 
11 abstract class ilBasePasswordEncoder implements ilPasswordEncoder
12 {
16  const MAX_PASSWORD_LENGTH = 4096;
17 
27  protected function comparePasswords($known_string, $user_string)
28  {
29  // Prevent issues if string length is 0
30  $known_string .= chr(0);
31  $user_string .= chr(0);
32 
33  $known_string_length = strlen($known_string);
34  $user_string_length = strlen($user_string);
35 
36  // Set the result to the difference between the lengths
37  $result = $known_string_length - $user_string_length;
38 
39  // Note that we ALWAYS iterate over the user-supplied length
40  // This is to prevent leaking length information
41  for($i = 0; $i < $user_string_length; $i++)
42  {
43  // Using % here is a trick to prevent notices
44  // It's safe, since if the lengths are different
45  // $result is already non-0
46  $result |= (ord($known_string[$i % $known_string_length]) ^ ord($user_string[$i]));
47  }
48 
49  // They are only identical strings if $result is exactly 0...
50  return 0 === $result;
51  }
52 
58  protected function isPasswordTooLong($password)
59  {
60  return strlen($password) > self::MAX_PASSWORD_LENGTH;
61  }
62 
66  public function isSupportedByRuntime()
67  {
68  return true;
69  }
70 
74  public function requiresSalt()
75  {
76  return false;
77  }
78 
82  public function requiresReencoding($encoded)
83  {
84  return false;
85  }
86 }
comparePasswords($known_string, $user_string)
Compares two passwords.
$result
requiresSalt()
{Returns whether or not the encoder requires a salt.boolean}
isSupportedByRuntime()
{Returns whether or not the encoder is supported by the runtime (PHP, HHVM, ...)boolean} ...
requiresReencoding($encoded)
{Returns whether or not the a encoded password needs to be re-encoded.string boolean} ...
isPasswordTooLong($password)
Checks if the password is too long.