csrf : update presentation

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@4914 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2019-01-30 14:34:42 +00:00
parent 5bba18b688
commit 5a4d86a44c

View File

@@ -1,12 +1,14 @@
<?php <?php
/** DomFramework /** DomFramework
@package domframework * @package domframework
@author Dominique Fournier <dominique@fournier38.fr> */ * @author Dominique Fournier <dominique@fournier38.fr>
*/
/** CSRF protection /** CSRF protection
* By default, the CSRF protection is active if a SESSION is active too. * By default, the CSRF protection is active if a SESSION is active too.
* It can be disabled if needed. An Exception is raised if the form is send * It can be disabled if needed. An Exception is raised if the form is send
* back without the token */ * back without the token
*/
class csrf class csrf
{ {
/** Allow to disable the csrf protection */ /** Allow to disable the csrf protection */
@@ -19,7 +21,8 @@ class csrf
* enter information in form and submit) */ * enter information in form and submit) */
private $csrfTimeout = 3600; private $csrfTimeout = 3600;
/** Manage the singleton */ /** Manage the singleton
*/
public function __construct () public function __construct ()
// {{{ // {{{
{ {
@@ -36,7 +39,8 @@ class csrf
} }
// }}} // }}}
/** This function return the token */ /** This function return the token
*/
public function createToken () public function createToken ()
// {{{ // {{{
{ {
@@ -54,7 +58,8 @@ class csrf
/** Check if the provided token is the right token, defined last displayed /** Check if the provided token is the right token, defined last displayed
* page * page
* @param string $tokenFromUser The value csrf the user's token */ * @param string $tokenFromUser The value csrf the user's token
*/
public function checkToken ($tokenFromUser) public function checkToken ($tokenFromUser)
// {{{ // {{{
{ {
@@ -80,7 +85,8 @@ class csrf
} }
// }}} // }}}
/** Return the CSRF token in a hidden field */ /** Return the CSRF token in a hidden field
*/
public function displayFormCSRF () public function displayFormCSRF ()
// {{{ // {{{
{ {
@@ -92,7 +98,8 @@ class csrf
} }
// }}} // }}}
/** Return the token if exists or create a new one if needed */ /** Return the token if exists or create a new one if needed
*/
public function getToken () public function getToken ()
// {{{ // {{{
{ {
@@ -110,6 +117,7 @@ class csrf
{ {
$this->checkToken ($tokenFromUser); $this->checkToken ($tokenFromUser);
$_SESSION["domframework"]["csrf"]["csrfStart"] = microtime (TRUE); $_SESSION["domframework"]["csrf"]["csrfStart"] = microtime (TRUE);
return true;
} }
// }}} // }}}
} }