Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //=======================================================================
- //== RaFaeL Security ==
- //=======================================================================
- class Security {
- private $xss = array(
- "htmlspecialchars" => true,
- "htmlentities" => true, //Don't use if strip_tags enabled
- "strip_tags" => false //Don't use if htmlentities enabled
- ), $sql = array(
- "stripslashes" => true,
- "mysql_real_escape_string" => true
- ), $settings = array(
- "REQUEST_ENCTYPE" => true,
- "DOUBLE_ENCTYPE" => true
- );
- function __construct($settings = array(), $enabled = array()) {
- foreach($enabled as $enable=>$value) {
- $this->SetFunc($enable, $value);
- }
- foreach($settings as $setting=>$value) {
- if(isset($this->settings[$setting]) && is_bool($value)) $this->settings[$setting] = $value;
- }
- if($this->settings["REQUEST_ENCTYPE"]) {
- foreach($_REQUEST as $name=>$value)
- $_REQUEST[$name] = $this->Sql($value);
- }
- }
- function Xss($str) {
- foreach($this->xss as $func=>$state) {
- if($state == true) $str = $func($str);
- }
- return $str;
- }
- function Sql($str) {
- foreach($this->sql as $func=>$state) {
- if($state == true) $str = $func($str);
- }
- return $str;
- }
- function SetFunc($enable, $value = true) {
- if(isset($this->xss[$enable]) && is_bool($value)) $this->Xss[$enable] = $value;
- else if(isset($this->sql[$enable]) && is_bool($value)) $this->Sql[$enable] = $value;
- return true;
- }
- function Enctype($str) {
- $str = hash('sha256', md5($str));
- return $this->settings["DOUBLE_ENCTYPE"]? (substr(hash('sha512', $str), strlen($str), strlen($str)*0.8)):($str);
- }
- }
- //Usage Example's:
- $Security = new Security(array("REQUEST_ENCTYPE" => false)); // $Security = new Security([Settings], [Disabled]);
- $Security->SetFunc("htmlentities", true);
- echo $Security->Xss("<html>'RaFaeL's Security class'</html>"); //<html>'RaFaeL's Security class'</html>
- echo "<br />";
- echo $Security->Sql("'RaFaeL's Security class'"); //\'RaFaeL\'s Security class\'
- echo "<br />";
- echo $_REQUEST["test"];
- echo "<br />";
- echo $Security->Enctype("RaFaeL"); //e980a7582c517886f2d80f88fd9a5a533a6fab71f3b4b04c8dcb1b59e4f2f033
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement