Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Dimoweb_login
- *
- * @package
- * @author Patrick Rennings
- * @copyright 2010
- * @version $Id$
- * @access public
- */
- class Dimoweb_login {
- static public $PrjID;
- static public $PrjCode;
- static public $RtnCode;
- protected $iUsername;
- protected $iPassword;
- protected $bProc;
- static protected $DbCon;
- /**
- * Dimoweb_login::__construct()
- *
- * @param int $ProjectID
- * @param mixed $ReportURL
- * @param mixed $Username
- * @param mixed $Password
- * @return
- */
- public function __construct ( $ProjectID = null, $ProjectCode = null, $TransactionID = null, $ReportURL = null, $Username = null, $Password = null )
- {
- if ( ! ctype_digit ( $ProjectID ) OR empty ( $ProjectID ) )
- {
- self::$RtnCode = '0001';
- }
- else
- {
- self::$PrjID = $ProjectID;
- }
- if ( strlen ( $ProjectCode ) != 64 OR empty ( $ProjectCode ) )
- {
- self::$RtnCode = '0008';
- }
- else
- {
- self::$PrjCode = $ProjectCode;
- }
- if ( empty ( $ReportURL ) AND empty ( self::$RtnCode ) )
- {
- self::$RtnCode = '0002';
- }
- /**
- *
- * Database connection
- * using PDO for the best speed
- *
- */
- try
- {
- self::$DbCon = new PDO ( 'mysql:dbname=patrick_dwl;host=localhost', 'patrick_dwl', 'dwlpatrick31' );
- }
- catch ( PDOException $e )
- {
- self::$RtnCode = '0999';
- }
- $this->CheckReturn( );
- if ( empty ( self::$RtnCode ) )
- {
- $this->iUsername = $Username;
- $this->iPassword = $Password;
- $this->ValidateProject ( );
- $this->ValidateTransaction ( $TransactionID );
- if ( empty ( self::$RtnCode ) )
- {
- $this->ValidateLogin ( );
- }
- }
- }
- /**
- * Dimoweb_login::ValidateProject()
- *
- * @return
- */
- protected function ValidateProject ( )
- {
- $iRquery = self::$DbCon->query( 'SELECT `project_id`, `project_key` FROM `projects`
- WHERE `project_id` = ' . self::$PrjID . '
- AND `project_key` = "' . self::$PrjCode . '" ' );
- if ( $iRquery->rowCount() < 1 )
- {
- self::$RtnCode = '0007';
- }
- $this->CheckReturn( );
- }
- /**
- * Dimoweb_login::ValidateLogin()
- *
- * @return
- */
- protected function ValidateLogin ( )
- {
- if ( empty ( $this->iUsername ) OR empty ( $this->iPassword ) )
- {
- self::$RtnCode = '0004';
- }
- else
- {
- $this->HashPassword( );
- if ( empty ( self::$RtnCode ) )
- {
- $cQuery = self::$DbCon->query( ' SELECT `username`, `password` FROM `users`
- WHERE `username` = "' . $this->iUsername . '"
- AND `password` = "' . $this->iPassword . '" ' );
- if ( $cQuery->rowCount() < 1 )
- {
- self::$RtnCode = '0005';
- }
- else
- {
- self::$RtnCode = '1000';
- }
- }
- }
- $this->CheckReturn ( );
- }
- protected function ValidateTransaction ( $TransID )
- {
- if ( ! ctype_digit ( $TransID ) )
- {
- self::$RtnCode = '0009';
- }
- else
- {
- $cQuery = self::$DbCon->query( ' SELECT `transaction_code`, `time` FROM `transactions`
- WHERE `transaction_code` = "' . $TransID . '"
- AND `time` >= NOW() - 10 ' );
- if ( $cQuery->rowCount() < 1 )
- {
- self::$RtnCode = '0010';
- }
- }
- $this->CheckReturn ( );
- }
- /**
- * Dimoweb_login::HashPassword()
- *
- * @return
- */
- protected function HashPassword ( )
- {
- if ( empty ( $this->iPassword ) )
- {
- self::$RtnCode = '0003';
- }
- else
- {
- $GenHash = hash ( 'sha512' , $this->iPassword );
- $this->iPassword = $GenHash;
- }
- $this->CheckReturn ( );
- }
- /**
- * Dimoweb_login::CheckReturn()
- *
- * @return
- */
- protected function CheckReturn ( )
- {
- if ( ! empty ( self::$RtnCode ) )
- {
- return self::$RtnCode;
- $this->bProc = false;
- }
- else
- {
- $this->bProc = true;
- }
- }
- }
- $login = new Dimoweb_login ( $_GET['prjid'], '75caa8138fe7be4372b81f17e3eec3d81068fc1d8b3ad504445f72d0fdd39210', '1234567890', $_GET['rurl'], $_GET['username'], $_GET['password'] );
- if ( Dimoweb_login::$RtnCode )
- {
- echo Dimoweb_login::$RtnCode;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement