PageRenderTime 101ms CodeModel.GetById 94ms app.highlight 4ms RepoModel.GetById 2ms app.codeStats 0ms

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

https://bitbucket.org/linxpinx/mercurial
PHP | 127 lines | 39 code | 9 blank | 79 comment | 7 complexity | 5d0047ca3229184c35e6c1bb9964a5e8 MD5 | raw file
  1<?php
  2/***************************************************************
  3*  Copyright notice
  4*
  5*  (c) 2009-2010 Marcus Krause <marcus#exp2009@t3sec.info>
  6*  All rights reserved
  7*
  8*  This script is part of the TYPO3 project. The TYPO3 project is
  9*  free software; you can redistribute it and/or modify
 10*  it under the terms of the GNU General Public License as published by
 11*  the Free Software Foundation; either version 2 of the License, or
 12*  (at your option) any later version.
 13*
 14*  The GNU General Public License can be found at
 15*  http://www.gnu.org/copyleft/gpl.html.
 16*  A copy is found in the textfile GPL.txt and important notices to the license
 17*  from the author is found in LICENSE.txt distributed with these scripts.
 18*
 19*
 20*  This script is distributed in the hope that it will be useful,
 21*  but WITHOUT ANY WARRANTY; without even the implied warranty of
 22*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 23*  GNU General Public License for more details.
 24*
 25*  This copyright notice MUST APPEAR in all copies of the script!
 26***************************************************************/
 27/**
 28 * Contains abstract class "tx_saltedpasswords_abstract_salts"
 29 * to be used in classes that provide salted hashing.
 30 *
 31 * $Id: class.tx_saltedpasswords_abstract_salts.php 7905 2010-06-13 14:42:33Z ohader $
 32 */
 33
 34
 35/**
 36 * Abtract class with methods needed to be extended
 37 * in a salted hashing class.
 38 *
 39 * @author      Marcus Krause <marcus#exp2009@t3sec.info>
 40 *
 41 * @abstract
 42 * @since   	2009-09-06
 43 * @package     TYPO3
 44 * @subpackage  tx_saltedpasswords
 45 */
 46abstract class tx_saltedpasswords_abstract_salts {
 47	/**
 48	 * Method applies settings (prefix, optional hash count, optional suffix)
 49	 * to a salt.
 50	 *
 51	 * @param	string		$salt:  a salt to apply setting to
 52	 * @return	string		salt with setting
 53	 */
 54	abstract protected function applySettingsToSalt($salt);
 55
 56	/**
 57	 * Generates a random base salt settings for the hash.
 58	 *
 59	 * @return	string		a string containing settings and a random salt
 60	 */
 61	abstract protected function getGeneratedSalt();
 62
 63	/**
 64	 * Returns a string for mapping an int to the corresponding base 64 character.
 65	 *
 66	 * @return	string		string for mapping an int to the corresponding base 64 character
 67	 */
 68	abstract protected function getItoa64();
 69
 70	/**
 71	 * Returns setting string to indicate type of hashing method.
 72	 *
 73	 * @return	string		setting string of hashing method
 74	 */
 75	abstract protected function getSetting();
 76
 77	/**
 78	 * Encodes bytes into printable base 64 using the *nix standard from crypt().
 79	 *
 80	 * @param	string		$input: the string containing bytes to encode.
 81	 * @param	integer		$count: the number of characters (bytes) to encode.
 82	 * @return	string		encoded string
 83	 */
 84	public function base64Encode($input, $count) {
 85		$output = '';
 86		$i = 0;
 87		$itoa64 = $this->getItoa64();
 88		do {
 89			$value = ord($input[$i++]);
 90			$output .= $itoa64[$value & 0x3f];
 91			if ($i < $count) {
 92				$value |= ord($input[$i]) << 8;
 93			}
 94			$output .= $itoa64[($value >> 6) & 0x3f];
 95			if ($i++ >= $count) {
 96				break;
 97			}
 98			if ($i < $count) {
 99				$value |= ord($input[$i]) << 16;
100			}
101			$output .= $itoa64[($value >> 12) & 0x3f];
102			if ($i++ >= $count) {
103				break;
104			}
105			$output .= $itoa64[($value >> 18) & 0x3f];
106		} while ($i < $count);
107		return $output;
108	}
109
110	/**
111	 * Method determines required length of base64 characters for a given
112	 * length of a byte string.
113	 *
114	 * @param	integer		$byteLength: length of bytes to calculate in base64 chars
115	 * @return	integer		required length of base64 characters
116	 */
117	protected function getLengthBase64FromBytes($byteLength) {
118			// calculates bytes in bits in base64
119		return intval(ceil(($byteLength * 8) / 6));
120	}
121}
122
123
124if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/saltedpasswords/classes/salts/class.tx_saltedpasswords_abstract_salts.php']) {
125	include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/saltedpasswords/classes/salts/class.tx_saltedpasswords_abstract_salts.php']);
126}
127?>