mercurial /typo3/sysext/saltedpasswords/classes/salts/class.tx_saltedpasswords_abstract_salts.php

Language PHP Lines 127
MD5 Hash 5d0047ca3229184c35e6c1bb9964a5e8 Estimated Cost $848 (why?)
Repository https://bitbucket.org/linxpinx/mercurial View Raw File
  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
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
/***************************************************************
*  Copyright notice
*
*  (c) 2009-2010 Marcus Krause <marcus#exp2009@t3sec.info>
*  All rights reserved
*
*  This script is part of the TYPO3 project. The TYPO3 project is
*  free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  The GNU General Public License can be found at
*  http://www.gnu.org/copyleft/gpl.html.
*  A copy is found in the textfile GPL.txt and important notices to the license
*  from the author is found in LICENSE.txt distributed with these scripts.
*
*
*  This script is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
 * Contains abstract class "tx_saltedpasswords_abstract_salts"
 * to be used in classes that provide salted hashing.
 *
 * $Id: class.tx_saltedpasswords_abstract_salts.php 7905 2010-06-13 14:42:33Z ohader $
 */


/**
 * Abtract class with methods needed to be extended
 * in a salted hashing class.
 *
 * @author      Marcus Krause <marcus#exp2009@t3sec.info>
 *
 * @abstract
 * @since   	2009-09-06
 * @package     TYPO3
 * @subpackage  tx_saltedpasswords
 */
abstract class tx_saltedpasswords_abstract_salts {
	/**
	 * Method applies settings (prefix, optional hash count, optional suffix)
	 * to a salt.
	 *
	 * @param	string		$salt:  a salt to apply setting to
	 * @return	string		salt with setting
	 */
	abstract protected function applySettingsToSalt($salt);

	/**
	 * Generates a random base salt settings for the hash.
	 *
	 * @return	string		a string containing settings and a random salt
	 */
	abstract protected function getGeneratedSalt();

	/**
	 * Returns a string for mapping an int to the corresponding base 64 character.
	 *
	 * @return	string		string for mapping an int to the corresponding base 64 character
	 */
	abstract protected function getItoa64();

	/**
	 * Returns setting string to indicate type of hashing method.
	 *
	 * @return	string		setting string of hashing method
	 */
	abstract protected function getSetting();

	/**
	 * Encodes bytes into printable base 64 using the *nix standard from crypt().
	 *
	 * @param	string		$input: the string containing bytes to encode.
	 * @param	integer		$count: the number of characters (bytes) to encode.
	 * @return	string		encoded string
	 */
	public function base64Encode($input, $count) {
		$output = '';
		$i = 0;
		$itoa64 = $this->getItoa64();
		do {
			$value = ord($input[$i++]);
			$output .= $itoa64[$value & 0x3f];
			if ($i < $count) {
				$value |= ord($input[$i]) << 8;
			}
			$output .= $itoa64[($value >> 6) & 0x3f];
			if ($i++ >= $count) {
				break;
			}
			if ($i < $count) {
				$value |= ord($input[$i]) << 16;
			}
			$output .= $itoa64[($value >> 12) & 0x3f];
			if ($i++ >= $count) {
				break;
			}
			$output .= $itoa64[($value >> 18) & 0x3f];
		} while ($i < $count);
		return $output;
	}

	/**
	 * Method determines required length of base64 characters for a given
	 * length of a byte string.
	 *
	 * @param	integer		$byteLength: length of bytes to calculate in base64 chars
	 * @return	integer		required length of base64 characters
	 */
	protected function getLengthBase64FromBytes($byteLength) {
			// calculates bytes in bits in base64
		return intval(ceil(($byteLength * 8) / 6));
	}
}


if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/saltedpasswords/classes/salts/class.tx_saltedpasswords_abstract_salts.php']) {
	include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/saltedpasswords/classes/salts/class.tx_saltedpasswords_abstract_salts.php']);
}
?>
Back to Top