PageRenderTime 56ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/typo3/sysext/sv/class.tx_sv_loginformhook.php

https://github.com/foxsoft/typo3v4core
PHP | 122 lines | 53 code | 13 blank | 56 comment | 7 complexity | f310e68b2269806d63dd352130ebffc0 MD5 | raw file
Possible License(s): Apache-2.0
  1. <?php
  2. /***************************************************************
  3. * Copyright notice
  4. *
  5. * (c) 2009-2010 Dmitry Dulepov <dmitry@typo3.org>
  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. *
  17. * This script is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * This copyright notice MUST APPEAR in all copies of the script!
  23. ***************************************************************/
  24. /**
  25. * [CLASS/FUNCTION INDEX of SCRIPT]
  26. *
  27. * $Id$
  28. */
  29. /**
  30. * This class contains a BE login form hook. It adds all necessary JavaScript
  31. * for the superchallenged authentication.
  32. *
  33. * @author Dmitry Dulepov <dmitry@typo3.org>
  34. * @package TYPO3
  35. * @subpackage tx_sv
  36. */
  37. class tx_sv_loginformhook {
  38. /**
  39. * Provides form code for the superchallenged authentication.
  40. *
  41. * @param array $params Parameters to the script
  42. * @param SC_index $pObj Calling object
  43. * @return string The code for the login form
  44. */
  45. public function getLoginFormTag(array $params, SC_index &$pObj) {
  46. // Get the code according to the login level
  47. switch ($pObj->loginSecurityLevel) {
  48. case 'challenged':
  49. case 'superchallenged':
  50. $_SESSION['login_challenge'] = $this->getChallenge();
  51. $content = '<form action="index.php" method="post" name="loginform" ' .
  52. 'onsubmit="doChallengeResponse(' .
  53. ($pObj->loginSecurityLevel == 'challenged' ? 0 : 1) . ');">' .
  54. '<input type="hidden" name="challenge" value="' .
  55. htmlspecialchars($_SESSION['login_challenge']) . '" />';
  56. break;
  57. case 'normal':
  58. $content = '<form action="index.php" method="post" name="loginform" onsubmit="document.loginform.userident.value=document.loginform.p_field.value;document.loginform.p_field.value=\'\';return true;">';
  59. break;
  60. default:
  61. // No code for unknown level!
  62. $content = '';
  63. }
  64. return $content;
  65. }
  66. /**
  67. * Provides form code for the superchallenged authentication.
  68. *
  69. * @param array $params Parameters to the script
  70. * @param SC_index $pObj Calling object
  71. * @return string The code for the login form
  72. */
  73. public function getLoginScripts(array $params, SC_index &$pObj) {
  74. $content = '';
  75. if ($pObj->loginSecurityLevel == 'superchallenged' ||
  76. $pObj->loginSecurityLevel == 'challenged') {
  77. $content = '
  78. <script type="text/javascript" src="md5.js"></script>
  79. ' . $GLOBALS['TBE_TEMPLATE']->wrapScriptTags('
  80. function doChallengeResponse(superchallenged) { //
  81. password = document.loginform.p_field.value;
  82. if (password) {
  83. if (superchallenged) {
  84. password = MD5(password); // this makes it superchallenged!!
  85. }
  86. str = document.loginform.username.value+":"+password+":"+document.loginform.challenge.value;
  87. document.loginform.userident.value = MD5(str);
  88. document.loginform.p_field.value = "";
  89. return true;
  90. }
  91. }
  92. ');
  93. }
  94. return $content;
  95. }
  96. /**
  97. * Create a random challenge string
  98. *
  99. * @return string Challenge value
  100. */
  101. protected function getChallenge() {
  102. $challenge = md5(uniqid('') . getmypid());
  103. return $challenge;
  104. }
  105. }
  106. if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/sv/class.tx_sv_loginformhook.php']) {
  107. include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/sv/class.tx_sv_loginformhook.php']);
  108. }
  109. ?>