Skip to content

Commit 6ad202f

Browse files
committed
Csrf 1.0.1
1 parent afc9b6b commit 6ad202f

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
<a name="1.0.1"></a>
2+
# [1.0.1](https://github.com/atomastic/csrf) (2021-02-09)
3+
* fix issue with token generation
4+
15
<a name="1.0.0"></a>
26
# [1.0.0](https://github.com/atomastic/csrf) (2021-02-08)
37
* Initial release

src/Csrf.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ class Csrf
3838
* @throws CsrfException
3939
*/
4040
public function __construct(
41-
string $tokenNamePrefix = '__csrf_name',
42-
string $tokenValuePrefix = '__csrf_value',
41+
string $tokenNamePrefix = '__csrf_token',
42+
string $tokenValuePrefix = '',
4343
int $strength = 32
4444
) {
4545
if ($strength < 32) {
@@ -53,14 +53,14 @@ public function __construct(
5353
);
5454
}
5555

56-
$this->tokenName = $tokenNamePrefix . $this->getRandomValue($strength);
57-
$this->tokenValue = $tokenValuePrefix . $this->getRandomValue($strength);
56+
$this->tokenName = $tokenNamePrefix;
5857

59-
if (array_key_exists($this->tokenName, $_SESSION)) {
60-
return;
58+
if (isset($_SESSION[$this->tokenName])) {
59+
$this->tokenValue = $_SESSION[$this->tokenName];
60+
} else {
61+
$this->tokenValue = $tokenValuePrefix . $this->getRandomValue($strength);
62+
$_SESSION[$this->tokenName] = $this->tokenValue;
6163
}
62-
63-
$_SESSION[$this->tokenName] = $this->tokenValue;
6464
}
6565

6666
/**

0 commit comments

Comments
 (0)