[PHP]Would this work?

Status
Not open for further replies.

Adil

DevBest CEO
May 28, 2011
1,278
716
PHP:
<?php
class Template
{
    public $salt = "tVaCYSAqNu6yjlIXWmcotT2SXL2Zrrl";
 
 
 
        public function secure($var)
        {
            return $this->mysql_real_escape($var);
            return $this-trim($var);
            return $this->stripslashes($var);
            return $this->htmlspecialchars($var);
            
        }
        public function encrypt($var)
        {
            return $this->sha512($var . $salt);
        }
}
 
//this is a basic template class, will add more later on. The sanitize function strips the given $_GET var
?>

PHP:
   <?php
      $username = $_POST['username'];
      $password = $_POST['password'];
      $email = $_POST['email'];
      
      $template->secure($username);
      $template->encrypt($username);
 
      $template->secure($password);
      $template->encrypt($password);
       
      $template->secure($email);
      $template->encrypt($email);
  
      
  
      ?>
Wondering if this would work :s
 

Heaplink

Developer & Designer
Nov 9, 2011
510
173
To be honest, you don't need to encrypt username with an SHA512 hash. Also a good idea is to run speed tests :)

But yeah, it would work.
 

Heaplink

Developer & Designer
Nov 9, 2011
510
173
Try with this

PHP:
<?php
class Template
{
    public $salt = "tVaCYSAqNu6yjlIXWmcotT2SXL2Zrrl";
 
        public function secure($var)
        {
            return $this->mysql_real_escape($var);
            return trim($var);
            return stripslashes($var);
            return htmlspecialchars($var);
         
        }
        public function encrypt($var)
        {
            return hash('sha512', $var . $salt);
        }
}
?>
 
<?php
      $template = new Template();
 
      $username = $_POST['username'];
      $password = $_POST['password'];
      $email = $_POST['email'];
   
      $template->secure($username);
      $template->encrypt($username); // Honestly, you don't need this...
 
      $template->secure($password) . '<br />';
      $template->encrypt($password) . '<br />' . '<br />';
   
      $template->secure($email) . '<br />';
      $template->encrypt($email) . '<br />';
?>
 

Adil

DevBest CEO
May 28, 2011
1,278
716
Try with this

PHP:
<?php
class Template
{
    public $salt = "tVaCYSAqNu6yjlIXWmcotT2SXL2Zrrl";
 
        public function secure($var)
        {
            //return $this->mysql_real_escape($var);
            return trim($var);
            return stripslashes($var);
            return htmlspecialchars($var);
         
        }
        public function encrypt($var)
        {
            return hash('sha512', $var . $salt);
        }
}
?>
 
<?php
      $template = new Template();
 
      $username = $_POST['username'];
      $password = $_POST['password'];
      $email = $_POST['email'];
   
      $template->secure($username);
      $template->encrypt($username); // Honestly, you don't need this...
 
      $template->secure($password) . '<br />';
      $template->encrypt($password) . '<br />' . '<br />';
   
      $template->secure($email) . '<br />';
      $template->encrypt($email) . '<br />';
?>
I know I don't need the username encrypted, it was just for the sake of context :p
I do declare
Code:
 $template = new Template();
In my global.php file
 

Heaplink

Developer & Designer
Nov 9, 2011
510
173
Allright, but look at the Template class changes - I removed the $this-> since you don't need the functions in your class, they're already predefined in PHP 5.

And also, use hash('sha512', '<value>') since sha512 is not a function in PHP 5.
 
Status
Not open for further replies.

Users who are viewing this thread

Top