Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 2008a86

Browse files
author
Jamie Snape
committed
Add an improved hash form element
1 parent eb64a00 commit 2008a86

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"ext-json": "*",
1818
"francodacosta/phmagick": "0.4.*@dev",
1919
"intervention/image": "~2.0.13",
20+
"ircmaxell/random-lib": "1.0.*@dev",
2021
"leafo/scssphp": "~0.1.1",
2122
"maennchen/zipstream-php": "~0.2.2",
2223
"michelf/php-markdown": "~1.4.1",
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
5+
All rights reserved.
6+
More information http://www.kitware.com
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0.txt
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
=========================================================================*/
20+
21+
/** Extend Zend Form Element Hash to generate a more random hash. */
22+
class Midas_Form_Element_Hash extends Zend_Form_Element_Hash
23+
{
24+
/** Generate a CSRF token. */
25+
protected function _generateHash()
26+
{
27+
$factory = new \RandomLib\Factory;
28+
$generator = $factory->getMediumStrengthGenerator();
29+
$random1 = $generator->generateString(32);
30+
$random2 = $generator->generateString(32);
31+
$this->_hash = hash('sha256', $random1.$this->getSalt().$this->getName().$random2);
32+
$this->setValue($this->_hash);
33+
}
34+
}

0 commit comments

Comments
 (0)