cgm225 Posted April 25, 2008 Share Posted April 25, 2008 How would you organize/code this class differently. I just don't feel like my organization is very good. Thanks in advance! $mysqli = new mysqli(MYSQL_SERVER,MYSQL_SERVER_USERNAME,MYSQL_SERVER_PASSWORD); class Authenication { //Declaring variables private $username; private $password; private $connection; //Setting username and password public function setUsernamePassword($username, $password) { $this->username = mysql_real_escape_string($username); $this->password = md5(mysql_real_escape_string($password)); } /* Passing MySQL connection, database, table, and field information to the class, all used to generate a database query for finding a matching username and password in the table */ public function databaseSettingsQuery($connection, $database, $table, $usernameField, $passwordField) { $connection->select_db($database); $this->result = $connection->query("SELECT * FROM $table WHERE $usernameField = '$this->username' AND $passwordField = '$this->password'"); } /* Results of the query are counted and, if greater than zero, $this->authorized is set to true and the provided username and password are passed to the setSession method */ public function Authorization() { $this->authorized = $this->result->num_rows > 0 ? TRUE : FALSE; $this->result->close(); if ($this->authorized) { $this->setSession($this->username, $this->password); } } //Setting the provided username and password to session variables public function setSession($username, $password) { $_SESSION['username'] = $username; $_SESSION['password'] = $password; } } $authentication = new Authenication(); $authentication->setUsernamePassword('user1','pass1'); $authentication->databaseSettingsQuery($mysqli, 'db_authentication', 'users', 'username', 'password'); $authentication->Authorization(); $mysqli->close(); Link to comment https://forums.phpfreaks.com/topic/102918-how-would-you-do-this-class-differently-i-just-dont-like-my-organization/ Share on other sites More sharing options...
DarkWater Posted April 25, 2008 Share Posted April 25, 2008 It looks okay, but you might want to spell Authentication correctly. =P Link to comment https://forums.phpfreaks.com/topic/102918-how-would-you-do-this-class-differently-i-just-dont-like-my-organization/#findComment-527178 Share on other sites More sharing options...
cgm225 Posted April 25, 2008 Author Share Posted April 25, 2008 Sorry about that lol Any other feedback? Link to comment https://forums.phpfreaks.com/topic/102918-how-would-you-do-this-class-differently-i-just-dont-like-my-organization/#findComment-527182 Share on other sites More sharing options...
DarkWater Posted April 25, 2008 Share Posted April 25, 2008 That code looks okay. It's organized well enough to function properly. xD Link to comment https://forums.phpfreaks.com/topic/102918-how-would-you-do-this-class-differently-i-just-dont-like-my-organization/#findComment-527195 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.