Jump to content

Recommended Posts

I'm trying to get a handle on OOP and classes by creating a user management system.  I've started with the login and I have a Login class and a Phash Class.  Phash creates a hashed and salted password.  And I call it from inside the Login class.  (I will have a Register class where I will use the Phash class in it too.)  I've removed some of the other stuff not relevant to the password operations.  And basically, I'm wondering if I'm doing this right.

 

<?php

class Login
{
  include('class.Phash.php');

  private $_salted;

  private $_password;
  private $_passhash;
  
  $salted = new Phash();

  public function __construct()
  {
    $this->_salted = "";

    $this->_password = ($this->_login)? $this->filter($_POST['password']) : '';
    $this->_passhash  = ($this->_login)? $this->_salted) : $_SESSION[_salted];
  }

   
    $data = mysql_query("SELECT ID FROM users WHERE username = '{$this->_username}' AND password = '{$this->_passhash}'");

 

<?php

class Phash
{

define('SALT_LENGTH', 20);


function generateHash($_password, $salt = null)
{
    if ($salt === null)
    {
        $salt = substr(md5(uniqid(rand(), true)), 0, SALT_LENGTH);
    }
    else
    {
        $salt = substr($salt, 0, SALT_LENGTH);
    }

    return $salt . sha1($salt . $plainText);
}
}
?>

Why are you creating an instance of Phash that you don't even use?

 

In your generateHash function, you don't even use the first argument...?

 

Not sure if you are aware, but php.net has excellent documentation on OOP...

 

http://php.net/manual/en/language.oop5.php

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.