Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class problem in php
- <?php
- try {
- require_once('./lib/testdb.php');
- $login = new Login();
- }
- catch(Exception $error) {
- print $error->getMessage();
- }
- /* Include the HTML for the form */
- require_once('./lib/form.php');
- ?>
- <?php
- define("DB_HOST", "localhost");
- define("DB_USER", "root");
- define("DB_PASS", "root");
- class Login{
- private $username;
- private $password;
- public function getUsername() {
- return $this->username;
- }
- public function getPassword() {
- return $this->password;
- }
- public function getEncryptedPassword() {
- return sha1($this->password);
- }
- public function connectToMySQL() {
- @mysql_connect(DB_HOST, DB_USER, DB_PASS) OR die("Cannot connect to MySQL server!");
- mysql_select_db("dd") OR die("Cannot select database!");
- }
- public function verifyLogin($username, $password) {
- $this->username = $username;
- if(empty($username) || empty($password)) {
- throw new Exception(Login::ERROR_EMPTY_LOGIN);
- }
- else {
- $query = sprintf("SELECT * FROM 'users' WHERE username = '%s' AND
- userpass = sha1('%s') ");
- $this->clean($username),
- $this->clean($password));
- $result = mysql_query($query) OR die('Cannot perform query!');
- while($info = mysql_fetch_array( $result ))
- {
- echo $info['username'];
- }
- }
- ?>
- --
- -- Database: `login`
- --
- -- --------------------------------------------------------
- --
- -- Table structure for table `login`
- --
- CREATE TABLE IF NOT EXISTS `login` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `username` varchar(80) NOT NULL,
- `password` varchar(80) NOT NULL,
- PRIMARY KEY (`id`)
- ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
- --
- -- Dumping data for table `login`
- --
- INSERT INTO `login` (`id`, `username`, `password`) VALUES
- (1, 'ajay', 'password');
- $query = sprintf("SELECT * FROM 'users' WHERE username = '%s' AND
- userpass = sha1('%s') "); // here
- $this->clean($username),
- $this->clean($password));
- $query = sprintf("SELECT * FROM 'users' WHERE username = '%s' AND
- userpass = sha1('%s') ", // corrected
- $this->clean($username),
- $this->clean($password));
- <?php
- try {
- require_once('./lib/testdb.php');
- $login = new Login();
- }
- $result = mysql_query($query) OR die('Cannot perform query: ' . mysql_error());
- echo $query;
Add Comment
Please, Sign In to add comment