Skip to content

Commit

Permalink
Csrf 1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Awilum committed Feb 9, 2021
1 parent afc9b6b commit 6ad202f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<a name="1.0.1"></a>
# [1.0.1](https://github.com/atomastic/csrf) (2021-02-09)
* fix issue with token generation

<a name="1.0.0"></a>
# [1.0.0](https://github.com/atomastic/csrf) (2021-02-08)
* Initial release
16 changes: 8 additions & 8 deletions src/Csrf.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class Csrf
* @throws CsrfException
*/
public function __construct(
string $tokenNamePrefix = '__csrf_name',
string $tokenValuePrefix = '__csrf_value',
string $tokenNamePrefix = '__csrf_token',
string $tokenValuePrefix = '',
int $strength = 32
) {
if ($strength < 32) {
Expand All @@ -53,14 +53,14 @@ public function __construct(
);
}

$this->tokenName = $tokenNamePrefix . $this->getRandomValue($strength);
$this->tokenValue = $tokenValuePrefix . $this->getRandomValue($strength);
$this->tokenName = $tokenNamePrefix;

if (array_key_exists($this->tokenName, $_SESSION)) {
return;
if (isset($_SESSION[$this->tokenName])) {
$this->tokenValue = $_SESSION[$this->tokenName];
} else {
$this->tokenValue = $tokenValuePrefix . $this->getRandomValue($strength);
$_SESSION[$this->tokenName] = $this->tokenValue;
}

$_SESSION[$this->tokenName] = $this->tokenValue;
}

/**
Expand Down

0 comments on commit 6ad202f

Please sign in to comment.