Jump to content

Trying to learn OOP and classes with login, need help.


nakins

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

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.