nakins Posted July 14, 2011 Share Posted July 14, 2011 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); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/242009-trying-to-learn-oop-and-classes-with-login-need-help/ Share on other sites More sharing options...
requinix Posted July 14, 2011 Share Posted July 14, 2011 Not quite. You can't put normal code in the middle of a class definition: only variables and functions. Move the include, $salted= outside, and define() outside. Quote Link to comment https://forums.phpfreaks.com/topic/242009-trying-to-learn-oop-and-classes-with-login-need-help/#findComment-1242817 Share on other sites More sharing options...
AyKay47 Posted July 14, 2011 Share Posted July 14, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/242009-trying-to-learn-oop-and-classes-with-login-need-help/#findComment-1242822 Share on other sites More sharing options...
nakins Posted July 15, 2011 Author Share Posted July 15, 2011 Yeah, it's all messed up. I was in a hurry to post it and didn't look it over. I was focused on getting Phash into Login and passing the argument and returning the value, trying to understand that. I'll try again. Quote Link to comment https://forums.phpfreaks.com/topic/242009-trying-to-learn-oop-and-classes-with-login-need-help/#findComment-1242917 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.